Groovy
  1. Groovy
  2. GROOVY-2914

LoadConfiguration fails to load *.jar

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.5.6
    • Fix Version/s: 1.8-rc-1, 1.7.9, 1.9-beta-1
    • Component/s: None
    • Labels:
      None
    • Environment:
      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.

        Activity

        Mark Thomas made changes -
        Workflow jira [ 12967223 ] Default workflow, editable Closed status [ 12974940 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12731932 ] Default workflow, editable Closed status [ 12743797 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Guillaume Delcroix made changes -
        Assignee Guillaume Laforge [ guillaume ]
        Fix Version/s 1.8-rc-1 [ 17132 ]
        Fix Version/s 1.9-beta-1 [ 17153 ]
        Status Open [ 1 ] Closed [ 6 ]
        Fix Version/s 1.7.x [ 15538 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.7.9 [ 17164 ]
        Jochen Theodorou made changes -
        Parent GROOVY-4683 [ 122027 ]
        Issue Type Sub-task [ 7 ] Bug [ 1 ]
        Jochen Theodorou made changes -
        Parent GROOVY-4683 [ 122027 ]
        Issue Type Bug [ 1 ] Sub-task [ 7 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.7-beta-x [ 15538 ]
        Fix Version/s 1.7-beta-1 [ 14014 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.6.3 [ 15251 ]
        Fix Version/s 1.7-beta-1 [ 14014 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.6.2 [ 15151 ]
        Fix Version/s 1.6.3 [ 15251 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.5.8 [ 14630 ]
        Fix Version/s 1.6.2 [ 15151 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.5.8 [ 14630 ]
        Fix Version/s 1.5.7 [ 14242 ]
        Fix Version/s 1.6-beta-2 [ 14261 ]
        Jochen Theodorou made changes -
        Field Original Value New Value
        Fix Version/s 1.6-beta-2 [ 14261 ]
        Fix Version/s 1.5.7 [ 14242 ]
        Klaus Kopruch created issue -

          People

          • Assignee:
            Guillaume Delcroix
            Reporter:
            Klaus Kopruch
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development