Christoffer Hammarström created GROOVY-8096: -----------------------------------------------
Summary: setScriptBaseClass with Java base class breaks @Field initialization from Binding due to wrong constructor Key: GROOVY-8096 URL: https://issues.apache.org/jira/browse/GROOVY-8096 Project: Groovy Issue Type: Bug Components: Compiler, GroovyScriptEngine Affects Versions: 2.4.8 Reporter: Christoffer Hammarström I created a pull request on GitHub with a failing test showing the problem: https://github.com/apache/groovy/pull/502 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}} {{ModuleNode.createStatementsClass()}} calls {{.getSuperClass().getDeclaredConstructor(SCRIPT_CONTEXT_CTOR)}} Then {{ClassNode.constructors}} is set to an empty ArrayList in {{ClassNode.getDeclaredConstructors()}}, insteaf of looking them up from the Java class. The script constructor is then generated in {{ModuleNode.createStatementsClass()}} as: {code:java} Constructor(Binding context) { super(); // Fields are initialized after the call to super() // Fields are initialized here without binding setBinding(context); // Fields are initialized before setBinding } {code} instead of {code:java} Constructor(Binding context) { super(context); // Fields are initialized after the call to super(context) } {code} We're calling the default constructor in the base class with {{super()}}, instead of passing along the {{Binding context}} with {{super(context)}} This breaks initialization of Fields that depend on the {{Binding context}}. Fields are initialized between the call to {{super()}} and the {{setBinding(context)}}: http://stackoverflow.com/a/14806340/233014 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. -- This message was sent by Atlassian JIRA (v6.3.15#6346)