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

Exception at runtime due to lambda analyzer reattributes live AST

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • None
    • 11
    • tools
    • b02
    • generic
    • generic

    Description

      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)" .

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: