Ivan Kuznetsov created GROOVY-8698:
--------------------------------------

             Summary: Double class initialization using 
groovy.lang.GroovyClassLoader
                 Key: GROOVY-8698
                 URL: https://issues.apache.org/jira/browse/GROOVY-8698
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.5.0, 2.4.15, 2.3.4
         Environment: OS: Windows 7, JVM: OpenJDK 10.0.1, Groovy: 2.5.0
            Reporter: Ivan Kuznetsov
         Attachments: output.txt, test.zip

I'm integrating Groovy DSL into developing java application, and I'm faced with 
this issue when did test runs.

What I'm trying to do:
1. GroovyClassLoader reads and parses all .groovy scripts from file system; 
some of these scripts - real scripts (class Script), others - real 
classes/enums;
2. instantiates and runs only Script classes, others are left as is in class 
loader.

I'm expecting that all scripts will use the same instances (in static fields or 
enums) of common classes to which they refer and which located in outer scripts.

But, first created Script instance loads its own class from outer script, 
initializes it and uses it, but all other Script instances use loaded classes 
and its static instances on step 1. This is reproducible on specified 
'affected' versions, so I suppose that it affects all versions.

I've created sample project and attached to this issue to show what's going on. 
This application does above steps. Scripts 
'model.concrete1.ConcreteModel1.groovy' and 
'model.concrete2.ConcreteModel2.groovy' are shared classes, other files are 
scripts that refer to these shared classes and print class'es hash code. When 
you run application, you will see output in which FirstScript refers to its own 
ConcreteModel class and other scripts refer to ConcreteModel class that holds 
GroovyClassLoader. If you rename FirstScript.groovy to WFirstScript.groovy, 
order will change and, at this moment, MainScript.groovy instead of 
FirstScript.groovy will use its own class.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to