Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8184989

Incorrect class file created when passing lambda in inner class constructor and outer is subclass

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 10
    • 8u141, 9
    • tools
    • None
    • b28
    • x86
    • linux_ubuntu

      The fix for JDK-8129740 is incomplete. It fails on cases when outer class is a subclass and the entities of it's superclass are referred to in lambda expression.

      Reproduced on:
      javac 1.8.0_141
      and
      javac from jdk9 build 9+178

      The test source:
      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)

            sadayapalam Srikanth Adayapalam (Inactive)
            apetushkov Andrey Petushkov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: