-
Bug
-
Resolution: Fixed
-
P3
-
24
-
b03
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8348457 | 24.0.1 | Maurizio Cimadamore | P3 | Resolved | Fixed | b04 |
JDK-8346090 | 24 | Maurizio Cimadamore | P3 | Resolved | Fixed | b29 |
JEP 492 spec: https://cr.openjdk.org/~gbierman/jep492/jep492-20241101/specs/flexible-constructor-bodies-jls.html
Assertion:
If C occurs in a static context, then i has no immediately enclosing instance. Let S be the nearest static method declaration, static field declaration, or static initializer that encloses the declaration of C. If the nearest static method declaration, static field declaration, or static initializer that encloses the class instance creation expression is not S, then a compile-time error occurs.
Class Local1 in the code sample below is declared as part of the static field initializer (in a static context), and it's instantiated in a different static context.
The instance creation is supposed to fail in this case, but it succeeds.
class Test {
static int field = switch (1) {
case 1 -> {
class Local1 {
class Local2 {
public static void m() {
new Local1(); // does not fail
}
}
}
yield 1;
}
default -> 2;
};
}
Assertion:
If C occurs in a static context, then i has no immediately enclosing instance. Let S be the nearest static method declaration, static field declaration, or static initializer that encloses the declaration of C. If the nearest static method declaration, static field declaration, or static initializer that encloses the class instance creation expression is not S, then a compile-time error occurs.
Class Local1 in the code sample below is declared as part of the static field initializer (in a static context), and it's instantiated in a different static context.
The instance creation is supposed to fail in this case, but it succeeds.
class Test {
static int field = switch (1) {
case 1 -> {
class Local1 {
class Local2 {
public static void m() {
new Local1(); // does not fail
}
}
}
yield 1;
}
default -> 2;
};
}
- backported by
-
JDK-8346090 JEP 492: instantiating local classes in a different static context should not be allowed
-
- Resolved
-
-
JDK-8348457 JEP 492: instantiating local classes in a different static context should not be allowed
-
- Resolved
-
- relates to
-
JDK-8345944 JEP 492: extending local class in a different static context should not be allowed
-
- Resolved
-
- links to
-
Commit(jdk24) openjdk/jdk/67b82516
-
Commit(master) openjdk/jdk/0ad64234
-
Review(jdk24) openjdk/jdk/22708
-
Review(master) openjdk/jdk/22679
(2 links to)