-
Bug
-
Resolution: Fixed
-
P4
-
None
-
b04
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8348438 | 24.0.1 | Gavin Bierman | P4 | Resolved | Fixed | b04 |
JDK-8346674 | 24 | Gavin Bierman | P4 | Resolved | Fixed | b30 |
This regards the PREVIEW JEP 492.
[The fix to the spec inJDK-8346100 was itself broken.]
The issue regards an anonymous class instance creation expression that creates an instance that is a *subclass of a local class that is in a static context*. For example:
```
class O {
static void foo(int x) { // static context, so no enclosing instance
class X { /* capture x */ } // inner local class in a static context
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 condition in the draft spec should read:
- 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. **If the direct
superclass of *C* is an inner local class *L* that occurs in a static
context, then let *S* be the nearest `static` method declaration,
`static` field declaration, or static initializer that encloses the
declaration of *L*. 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 fix to the spec in
The issue regards an anonymous class instance creation expression that creates an instance that is a *subclass of a local class that is in a static context*. For example:
```
class O {
static void foo(int x) { // static context, so no enclosing instance
class X { /* capture x */ } // inner local class in a static context
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 condition in the draft spec should read:
- 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. **If the direct
superclass of *C* is an inner local class *L* that occurs in a static
context, then let *S* be the nearest `static` method declaration,
`static` field declaration, or static initializer that encloses the
declaration of *L*. 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.**
- backported by
-
JDK-8346674 15.9.2: Fix the assertion regarding instantiation of an anonymous class
-
- Resolved
-
-
JDK-8348438 15.9.2: Fix the assertion regarding instantiation of an anonymous class
-
- Resolved
-
- relates to
-
JDK-8346100 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
-