GitHub user kreiger opened a pull request:

    https://github.com/apache/groovy/pull/502

    CompilerConfiguration.setScriptBaseClass with Java class calls super() 
instead of super(Binding)

    This test fails because `ModuleNode.setScriptBaseClassFromConfig(ClassNode)`
    calls `.setSuperClass(ClassHelper.make(baseClassName))` on the 
`scriptDummy` `ClassNode`.
    
     The `ClassNode` created for this script's base class has `.lazyInitDone = 
true` and `.constructors = null` so when 
`.getSuperClass().getDeclaredConstructor(SCRIPT_CONTEXT_CTOR)` is called by 
`ModuleNode.createStatementsClass()`, then `ClassNode.constructors` is set to 
an empty ArrayList in `ClassNode.getDeclaredConstructors()`
    
    The script constructor is then generated as
    
             Constructor(Binding context) {
                 super();                   // Fields are initialized after the 
call to super()
                                            // Fields are initialized here
                 setBinding(context);       // Fields are initialized before 
the call to setBinding(context)
             }
    
    instead of
    
             Constructor(Binding context) {
                 super(context);            // Fields are initialized after the 
call to super(context)
             }
    
    Fields are initialized between the call to super() and the 
setBinding(context)
    which means Field initializers don't have access to the Binding context.
    
    This leads to `MissingPropertyException` because we're trying to look up 
variables from the `new Binding()` created in the default constructor, instead 
of the binding we passed in.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/kreiger/groovy 
setscriptbaseclass-calls-wrong-constructor

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/502.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #502
    
----
commit 764388a34b9f6fbf1c605fbbf02700b8ebed82d8
Author: Christoffer Hammarström <[email protected]>
Date:   2017-02-22T01:18:52Z

    Add tests to prove that calling CompilerConfiguration.setScriptBaseClass 
with a Java class causes ModuleNode to generate a constructor that prevents 
Field initialization from Binding context.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to