[ 
https://issues.apache.org/jira/browse/GROOVY-7670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15244830#comment-15244830
 ] 

JAMIE ECHLIN commented on GROOVY-7670:
--------------------------------------

Sorry for bringing this up again after so long, but I've done some more 
investigation and would appreciate any pointers.

{code}
def engine = new GroovyScriptEngine([new File("/some/path").toURL()] as URL[])
engine.run("foo/bar/File-With_Hypens.groovy", new Binding()) // this works

def script = engine.createScript("foo/bar/File-With_Hypens.groovy", new 
Binding()) // this creates the script instance
script.run()  // this fails with: java.lang.ClassFormatError: Illegal class 
name "foo/bar/File-With_Hypens$run" in class file foo/bar/File-With_Hypens$run

// but with java class:
public class SillyHack {
    public static Object run(Script script) {
        return script.run();
    }
}

// this works
SillyHack.run(scriptInstance)
{code}

As you can see, it seems that the problem only happens when calling .run from 
groovy land... if called from a java class there is no problem, hence the use 
of the silly hack. 

I'm just trying to separate the compiling of the script from the execution, due 
to some deadlocking issues.

> CLONE - dash in script filename
> -------------------------------
>
>                 Key: GROOVY-7670
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7670
>             Project: Groovy
>          Issue Type: Bug
>          Components: class generator
>    Affects Versions: 2.4.5
>         Environment: Oracle Java 8, Windows (although OS is not relevant IMHO)
>            Reporter: Christoph Grothaus
>            Priority: Minor
>         Attachments: fibonacci-numbers.groovy, fibonacci_numbers.groovy
>
>
> Cannot create script with dash ("-") in filename.
> Please try to run the two attached groovy scripts. The one with an underscore 
> in the filename runs happily (don't wonder, it gives no output). The one with 
> a dash in the filename gives this error: {noformat}$ groovy 
> fibonacci-numbers.groovy
> Caught: java.lang.ClassFormatError: Illegal class name 
> "fibonacci-numbers$fib" in class file fibonacci-numbers$fib
> java.lang.ClassFormatError: Illegal class name "fibonacci-numbers$fib" in 
> class file fibonacci-numbers$fib
>         at fibonacci-numbers.run(fibonacci-numbers.groovy:5){noformat}
> It really took me some time to figure out that the dash was causing this. I 
> would like to see Groovy allowing dashes in script filenames. If that should 
> be impossible, at least the error message should cleary indicate that I have 
> used an illegal character in the script filename.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to