Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.2.1, 2.2.2
-
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.