-
Bug
-
Resolution: Fixed
-
P3
-
None
-
master
Consider this program:
class StaticNewInnerTest {
public static void main(String[] args) {
class Local1 {
{ System.out.println(args); }
}
class Local2 {
static Local1 x = new Local1(); // 1
}
}
}
The local class creation in (1) is problematic: it occurs in a context where we no longer have access to the local variable that are captured by Local1 (namely "args").
JLS 15.9.2 has some rules around local class creation, but they are too weak to detect cases like this. Note also how this is a "new" problem, as it used not to be ok to declare static members inside local classes.
class StaticNewInnerTest {
public static void main(String[] args) {
class Local1 {
{ System.out.println(args); }
}
class Local2 {
static Local1 x = new Local1(); // 1
}
}
}
The local class creation in (1) is problematic: it occurs in a context where we no longer have access to the local variable that are captured by Local1 (namely "args").
JLS 15.9.2 has some rules around local class creation, but they are too weak to detect cases like this. Note also how this is a "new" problem, as it used not to be ok to declare static members inside local classes.