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

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: repo-amber
    • Fix Version/s: repo-amber
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      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) {

      }

        Attachments

          Activity

            People

            • Assignee:
              sadayapalam Srikanth Adayapalam
              Reporter:
              sadayapalam Srikanth Adayapalam
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: