-
Bug
-
Resolution: Fixed
-
P4
-
None
-
b03
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8348435 | 24.0.1 | Gavin Bierman | P4 | Resolved | Fixed | b04 |
JDK-8346110 | 24 | Gavin Bierman | P4 | Resolved | Fixed | b29 |
This regards the PREVIEW JEP 492:
Consider this case:
```
class O {
static void foo(int x) { // static context, so no enclosing instance
class X { /* capture x */ }
class U {
static void test() { new X(){...}; } // just as bad as saying `new X()`
}
}
}
```
The anonymous class instance creation expression should be forbidden (as it would be if it was just `new X()`). The rule given in the draft spec says:
- If C is an anonymous class, then:
- If the class instance creation expression 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.
The text "... that encloses the declaration of C" is incorrect and should read "... that encloses the declaration of **the direct superclass or direct superinterface** of C"
Consider this case:
```
class O {
static void foo(int x) { // static context, so no enclosing instance
class X { /* capture x */ }
class U {
static void test() { new X(){...}; } // just as bad as saying `new X()`
}
}
}
```
The anonymous class instance creation expression should be forbidden (as it would be if it was just `new X()`). The rule given in the draft spec says:
- If C is an anonymous class, then:
- If the class instance creation expression 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.
The text "... that encloses the declaration of C" is incorrect and should read "... that encloses the declaration of **the direct superclass or direct superinterface** of C"
- backported by
-
JDK-8346110 15.9.2: Assertion regarding local class creation and static contexts should refer to direct superclass of the anonymous class, not the anonymous class itself
-
- Resolved
-
-
JDK-8348435 15.9.2: Assertion regarding local class creation and static contexts should refer to direct superclass of the anonymous class, not the anonymous class itself
-
- Resolved
-
- relates to
-
JDK-8346380 15.9.2: Fix the assertion regarding instantiation of an anonymous class
-
- Resolved
-