You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Keith Suderman <su...@anc.org> on 2018/09/29 19:52:48 UTC
Bug or expected behaviour?
Hello,
I have a parent class that defines a static final String and a child class that references the String in it's constructor. Essentially:
class Parent {
static final String DEFAULT = 'default'
}
class Child extends Parent {
String value
Child() { this(DEFAULT) } // Bad type on operand stack
Child(String value) { this.value = value }
}
println new Child().value
However, when I try to run the code I get a "java.lang.VerifyError: Bad type on operand stack" (see below). From my understanding this exception is caused when a constructor tries to use a variable/field that has not been initialized yet; i.e. the `this(DEFAULT)` in the above example. However, if I qualify the DEFAULT with the class name (i.e. `this(Parent.DEFAULT)`) the code works as expected.
Similar code in Java works without DEFAULT being qualified with the superclass name. So I am wondering; is this a bug or a design decision that was made somewhere/sometime?
I am using Groovy Version: 2.5.2 JVM: 1.8.0_40 Vendor: Oracle Corporation OS: Mac OS X
Cheers,
Keith
Caught: java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
Child.<init>()V @10: invokeinterface
Reason:
Type uninitializedThis (current frame, stack[2]) is not assignable to 'java/lang/Object'
Current Frame:
bci: @10
flags: { flagThisUninit }
locals: { uninitializedThis, '[Lorg/codehaus/groovy/runtime/callsite/CallSite;' }
stack: { uninitializedThis, 'org/codehaus/groovy/runtime/callsite/CallSite', uninitializedThis }
Bytecode:
0x0000000: b800 114c 2a2b 1212 322a b900 1802 00b8
0x0000010: 001e c000 20b7 0023 b1