Details
-
Sub-task
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.7.2
-
None
-
None
-
WinXP - Groovy 1.7.x
Description
When a script defines and uses another class, the scriptCache entry in GroovyScriptEngine gets overwritten with the class defined inside the script rather than just containing the class of the script. This causes the script to fail when it is executed the second time because the wrong class is getting loaded from the cache. For example:
File FooScript.groovy
-----------------------
println "Running FooScript.groovy"
class Foo {
String bar()
}
assert new Foo().bar() == "bar"
My test script is defined as:
GseTest.groovy
--------------
println "Groovy Version = ${GroovySystem.version}"
def gse = new GroovyScriptEngine(".")
println "Run 1"
gse.run("FooScript.groovy", new Binding())
println "Run 2"
gse.run("FooScript.groovy", new Binding())
This produces the following output:
Groovy Version = 1.7.2
Run 1
Running FooScript.groovy
Run 2
Caught: groovy.lang.MissingMethodException: No signature of method: Foo.main() is applicable for argument types: ([Ljava.lang.String values: [[]]
Possible solutions: wait(), wait(long), bar(), any(), wait(long, int), each(groovy.lang.Closure)
at GseTest.run(GseTest.groovy:8)
We have a number of Groovlets that use this approach, and the bug was exposed when we upgraded from Groovy 1.6.x to 1.7.x.