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

Compiling a source with a URL pointing to the current working directory produces incorrectly named classes for top-level closures

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.1, 2.2.2
    • Fix Version/s: 2.3.0-beta-1, 2.2.3
    • Component/s: Compiler
    • Labels:
      None

      Description

      I identified this problem while diagnosing a bug reported against Spring Boot.

      It's probably best described with an example:

      GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
      CompilationUnit compilationUnit = new CompilationUnit(groovyClassLoader);
      compilationUnit.addSource(new URL("file:foo.groovy"));
      compilationUnit.compile();
      
      CompileUnit ast = compilationUnit.getAST();
      System.out.println(ast.getClasses());
      

      Compiling the above, and running it with a file named foo.groovy in the current working directory with the contents:

      foo {
      
      }
      

      will produce the output:

      [file:foo]
      

      I would expect the class to be named foo, not file:foo. This is the result if foo.groovy is moved into a directory named foo and the URL used to reference it becomes file:foo/foo.groovy.

      I believe the problem lies in org.codehaus.groovy.ast.ModuleNode.extractClassFromFileDescription() as it does not consider a URL that contains no slashes. As a result it never strips off the file: prefix.

        Attachments

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              awilkinson Andy Wilkinson
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: