FULL PRODUCT VERSION :
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin vmac769.laudert.intra 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
When i give an object created by an lambda expression using a non static method to a super-constructor, the compiler generates invlaid bytecode.
When in the attached code the method foo is static wverything is fine.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the given code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception.
ACTUAL -
And runtime exception within the JVM
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
TestClass$TestSubFunction.<init>(LTestClass;)V @8: invokedynamic
Reason:
Type uninitializedThis (current frame, stack[2]) is not assignable to 'TestClass$TestSubFunction'
Current Frame:
bci: @8
flags: { flagThisUninit }
locals: { uninitializedThis, 'TestClass' }
stack: { uninitializedThis, 'TestClass', uninitializedThis }
Bytecode:
0x0000000: 2a2b b500 012a 2b2a ba00 0200 00b7 0003
0x0000010: b1
at TestClass.bar(TestClass.java:8)
at TestClass.main(TestClass.java:4)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TestClass {
public static void main(String[] args) {
new TestClass().bar();
}
public void bar() {
new TestSubFunction();
}
private boolean foo(Long l) {
return l < 12L;
}
private interface MyPredicate {
boolean run(Long l);
}
private class TestFunctional {
public TestFunctional(MyPredicate predicate) {
}
}
private class TestSubFunction extends TestFunctional {
public TestSubFunction() {
super(l -> foo(34L));
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Make foo static or use explicit object creation instead.