[
https://issues.apache.org/jira/browse/GROOVY-136?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles updated GROOVY-136:
-------------------------------
Labels: ClassFormatError (was: )
> parser chokes on file names beginning with the slash symbol
> -----------------------------------------------------------
>
> Key: GROOVY-136
> URL: https://issues.apache.org/jira/browse/GROOVY-136
> Project: Groovy
> Issue Type: Bug
> Components: ast builder
> Reporter: Sergey Udovenko
> Assignee: Bob Paulin
> Priority: Minor
> Labels: ClassFormatError
> Fix For: 1.0-beta-3
>
>
> 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;
--
This message was sent by Atlassian Jira
(v8.20.7#820007)