Bug or expected behaviour?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug or expected behaviour?

Suderman Keith
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   

----------------------
Keith Suderman
Research Associate
Department of Computer Science
Vassar College, Poughkeepsie NY





signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Bug or expected behaviour?

Daniel.Sun
Hi Keith,

     I think this is a bug. Please submit a JIRA issue to track.

Cheers,
Daniel.Sun




-----
Daniel Sun
Apache Groovy committer
Blog: http://blog.sunlan.me 
Twitter: @daniel_sun

--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Daniel Sun
Apache Groovy committer

Blog: http://blog.sunlan.me
Twitter: @daniel_sun