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

[local-methods] Compiler fails to capture `this' when a class is declared inside a local method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • repo-amber
    • repo-amber
    • tools
    • generic
    • generic

      JDK-8232931 could be hiding this bug from showing up: From code review of com.sun.tools.javac.comp.LambdaToMethod.LambdaAnalyzerPreprocessor#visitClassDef, I suspect that we may have trouble with properly translating this code:


      public class X {
          Object foo() {
              int x = 42;
              System.out.println("In foo");
              Object goo() {
                  System.out.println("In goo");
                  class Y {
                  }
                  return new Y();
              }
              return goo();
          }
          public static void main(String [] args) {
              Object o = new X().foo();
              System.out.println(o);
          }
      }

      This is because, if a class is defined within a local method, the local method must capture its enclosing instance (if any) as it does for classes within a lambda. The relevant code triggers only for
      lambda enclosure case since it is guarded by

      if (directlyEnclosingLambda() != null) {

      }

            vromero Vicente Arturo Romero Zaldivar
            sadayapalam Srikanth Adayapalam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: