You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eduardo (Jira)" <ji...@apache.org> on 2023/01/04 14:36:00 UTC
[jira] [Commented] (GROOVY-10876) GroovyScriptEngineImpl cache bug
[ https://issues.apache.org/jira/browse/GROOVY-10876?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17654489#comment-17654489 ]
Eduardo commented on GROOVY-10876:
----------------------------------
I also tested with Groovy 4.0.7, but same output
> GroovyScriptEngineImpl cache bug
> --------------------------------
>
> Key: GROOVY-10876
> URL: https://issues.apache.org/jira/browse/GROOVY-10876
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.6
> Reporter: Eduardo
> Priority: Major
>
> GroovyScriptEngineImpl seems not to work correctly when reusing classes. The classes are being cached and this does not work correctly.
> A simple testcase which demonstrates the problem:
> {code:java}
> def simpleJavaClass = """
> public class SimpleClass {
> public String getMessage() {
> return new SimpleClass2().getMessage();
> }
> }
> """
> def simpleJavaClass2 = """
> public class SimpleClass2 {
> private final String message;
> public SimpleClass2() {
> message = "Some text created by John";
> }
>
> public String getMessage() {
> return message;
> }
> }
> """
> def main = """
> SimpleClass simpleClass = new SimpleClass()
> return simpleClass.getMessage()
> """
> println GroovySystem.version
> println System.getProperty("java.version")
> e = new org.codehaus.groovy.jsr223.GroovyScriptEngineImpl()
> println "Starting"
>
> println e.eval(simpleJavaClass2)
> println e.eval(simpleJavaClass)
> println e.eval(main)
>
> println "waiting..."
> sleep(2000)
>
> simpleJavaClass2 = simpleJavaClass2.replace("John", "Catalina")
>
> //println simpleJavaClass2
> println e.eval(simpleJavaClass2)
> println e.eval(simpleJavaClass)
> println e.eval(main){code}
> Output:
> {code:java}
> 4.0.6
> 17.0.5
> Starting
> class SimpleClass2
> class SimpleClass
> Some text created by John
> waiting...
> class SimpleClass2
> class SimpleClass
> Some text created by John {code}
> Expected:
> {code:java}
> 4.0.6
> 17.0.5
> Starting
> class SimpleClass2
> class SimpleClass
> Some text created by John
> waiting...
> class SimpleClass2
> class SimpleClass
> Some text created by Catalina {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)