RFR: JDK-8184989. Incorrect class file created when passing lambda in inner class constructor and outer is subclass
Andrey Petushkov
andrey.petushkov at gmail.com
Mon Jul 31 14:30:53 UTC 2017
Dear Compiler Team,
We’ve occasionally found out that there is a problem in javac related to lambda support, in part related to referencing the outer’s entity which otherwise would be captured by using inner this, but cannot be since it’s not yet fully initialized. More specifically this seem to be omission in the fix for JDK-8129740 <https://bugs.openjdk.java.net/browse/JDK-8129740>:
it's fix works fine if it deals with the entity from the outer class(es), but fails if the entity is inherited from outer’s parent. Consider the following source code:
A.java
public class A {
public boolean test(){
return true;
}
class AA{
public AA(Condition condition) {
}
}
}
Condition.java
public interface Condition<T> {
boolean check(T t);
}
B.java
public class B extends A {
private final BA myBA;
public B() {
myBA = new BA();
}
public class BA extends AA{
public BA() {
super(o -> test());
}
}
public static void main(String[] args) {
B b = new B();
System.out.println(b);
}
}
source compiles but execution of B fails with:
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
B$BA.lambda$new$0(LB;Ljava/lang/Object;)Z @1: getfield
Reason:
Type 'B' (current frame, stack[0]) is not assignable to 'B$BA'
Current Frame:
bci: @1
flags: { }
locals: { 'B', 'java/lang/Object' }
stack: { 'B' }
Bytecode:
0x0000000: 2ab4 0001 b600 04ac
at B.<init>(B.java:6)
at B.main(B.java:17)
The problem is reproduced on both latest 8u and 9 (by the time of the bug submission)
My naive attempt to fix could be seen here http://cr.openjdk.java.net/~apetushkov/8184989/webrev/ <http://cr.openjdk.java.net/~apetushkov/8184989/webrev/> (based on latest 8u)
Please could you consider reviewing/improving it or suggesting improvement direction as appropriate
Thanks,
Andrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20170731/e24e6a6f/attachment-0001.html>
More information about the compiler-dev
mailing list