-
Bug
-
Resolution: Unresolved
-
P4
-
repo-amber
-
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) {
}
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) {
}