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

Exception at runtime due to lambda analyzer reattributes live AST

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 11
    • None
    • tools
    • b02
    • generic
    • generic

      Below code throws exception when run with -XDfind=lambda at compile time.
      public class AnalyzerNotCopyingTest {
          public static void main(String... args) {
              new AnalyzerNotCopyingTest().run();
          }
          private void run() {
              Base b = new Base() {
                  public void run() {
                      test(this);
                  }
              };
              b.run();
          }
          private static void test(AnalyzerNotCopyingTest t) {
              throw new AssertionError("Should not be invoked!");
          }
          private static void test(Base b) {
                  //ok to invoke
          }
          public static interface Base {
              public abstract void run();
          }
      }

      javac -XDfind=lambda AnalyzerNotCopyingTest.java
      java AnalyzerNotCopyingTest

      Exception in thread "main" java.lang.NoSuchFieldError: this
              at AnalyzerNotCopyingTest$1.run(AnalyzerNotCopyingTest.java:16)
              at AnalyzerNotCopyingTest.run(AnalyzerNotCopyingTest.java:19)
              at AnalyzerNotCopyingTest.main(AnalyzerNotCopyingTest.java:10)

      This happens mainly because the lambda analyzer reattributes the live AST for "test(this)" .

            sdama Srinivas Dama (Inactive)
            sdama Srinivas Dama (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: