Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
Description
The following code will trow "java.lang.ClassFormatError: /script (Illegal Class name "/script")":
GroovyClassLoader cl = new GroovyClassLoader();
InputStream is = new ByteArrayInputStream("println('oops!')".getBytes());
cl.parseClass(is, "/script.groovy");
The problem is that method org.codehaus.groovy.ast.ModuleNode.extractClassFromFileDescription() ignores first slash in the file name producing illegal class name.
Here is the patch:
Index: groovy/groovy-core/src/main/org/codehaus/groovy/ast/ModuleNode.java
===================================================================
RCS file: /scm/cvspublic/groovy/groovy-core/src/main/org/codehaus/groovy/ast/ModuleNode.java,v
retrieving revision 1.15
diff -u -r1.15 ModuleNode.java
— groovy/groovy-core/src/main/org/codehaus/groovy/ast/ModuleNode.java 16 Jan 2004 19:17:22 -0000 1.15
+++ groovy/groovy-core/src/main/org/codehaus/groovy/ast/ModuleNode.java 18 Jan 2004 23:19:40 -0000
@@ -244,11 +244,11 @@
}
// new lets trip the path separators
idx = answer.lastIndexOf('/');
- if (idx > 0) {
+ if (idx != -1) { answer = answer.substring(idx + 1); }
idx = answer.lastIndexOf(File.separatorChar);
- if (idx > 0) {
+ if (idx != -1) { answer = answer.substring(idx + 1); }return answer;