Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2914

LoadConfiguration fails to load *.jar

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 1.5.6
    • 1.8-rc-1, 1.7.9, 1.9-beta-1
    • None
    • None
    • Windows XP, Groovy 1.5.6

    Description

      In my project I have a starter config like this:

       
      # load project resources
          load *.jar
      

      which causes groovy to fail with the following exception

      exception while configuring main class loader:
      java.lang.StringIndexOutOfBoundsException: String index out of range: -1
              at java.lang.String.substring(String.java:1768)
              at org.codehaus.groovy.tools.LoaderConfiguration.loadFilteredPath(LoaderConfiguration.java:193)
              at org.codehaus.groovy.tools.LoaderConfiguration.configure(LoaderConfiguration.java:113)
              at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:81)
              at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
      

      This can be fixed in LoaderConfiguration.java as follows:

      /**
        * load a possible filtered path. Filters are defined
        * by using the * wildcard like in any shell
        */
      private void loadFilteredPath(String filter) {
        if (filter==null) return;
          int starIndex = filter.indexOf(WILDCARD);
          if (starIndex == -1) {
            addFile(new File(filter));
            return;
          }
          boolean recursive = filter.indexOf(ALL_WILDCARD) != -1;
              
          String startDir = starIndex == 0 ? "./" : filter.substring(0, starIndex - 1);
          File root = new File(startDir);
      
          filter = RegexUtils.quote(filter);
          filter = filter.replaceAll("\\"+WILDCARD+"\\"+WILDCARD, MATCH_ALL);
          filter = filter.replaceAll("\\" + WILDCARD, MATCH_FILE_NAME);
          Pattern pattern = Pattern.compile(filter);
      
          final File[] files = root.listFiles();
          if (files != null) {
            findMatchingFiles(files, pattern, recursive);
          }
      }
      

      In the above method implementation the line

      String startDir = filter.substring(0, starIndex - 1);

      which caused the mentioned exception, was changed to

      String startDir = starIndex == 0 ? "./" : filter.substring(0, starIndex - 1);
      

      as you see.

      Attachments

        Activity

          People

            guillaume Guillaume Sauthier
            klaus.kopruch@materna.de Klaus Kopruch
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: