-
Bug
-
Resolution: Fixed
-
P4
-
21, 22
-
b22
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8320779 | 21.0.2 | Aleksey Shipilev | P4 | Resolved | Fixed | b09 |
If the following test is run in a subthread, a ClassCastException is thrown. It should be a NoSuchElementException.
```
/*
* @test
* @enablePreview
* @run main/othervm -Xmx10m TestProviderLeak
*/
public class UnboundValueTest {
public static void main(String [] args) throws Exception {
try {
java.util.Arrays.fill(new int[Integer.MAX_VALUE][], new
int[Integer.MAX_VALUE]);
} catch (OutOfMemoryError e) {
ScopedValue.newInstance().get();
}
}
}
```
```
java.lang.ClassCastException: class java.lang.Class cannot be cast to
class java.lang.ScopedValue$Snapshot (java.lang.Class and
java.lang.ScopedValue$Snapshot are in module java.base of loader
'bootstrap')
at
java.base/java.lang.ScopedValue.scopedValueBindings(ScopedValue.java:813)
at java.base/java.lang.ScopedValue.findBinding(ScopedValue.java:731)
at java.base/java.lang.ScopedValue.slowGet(ScopedValue.java:698)
at java.base/java.lang.ScopedValue.get(ScopedValue.java:693)
at TestProviderLeak.main(TestProviderLeak.java:11)
at
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at
com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
at java.base/java.lang.Thread.run(Thread.java:1570)
```
```
/*
* @test
* @enablePreview
* @run main/othervm -Xmx10m TestProviderLeak
*/
public class UnboundValueTest {
public static void main(String [] args) throws Exception {
try {
java.util.Arrays.fill(new int[Integer.MAX_VALUE][], new
int[Integer.MAX_VALUE]);
} catch (OutOfMemoryError e) {
ScopedValue.newInstance().get();
}
}
}
```
```
java.lang.ClassCastException: class java.lang.Class cannot be cast to
class java.lang.ScopedValue$Snapshot (java.lang.Class and
java.lang.ScopedValue$Snapshot are in module java.base of loader
'bootstrap')
at
java.base/java.lang.ScopedValue.scopedValueBindings(ScopedValue.java:813)
at java.base/java.lang.ScopedValue.findBinding(ScopedValue.java:731)
at java.base/java.lang.ScopedValue.slowGet(ScopedValue.java:698)
at java.base/java.lang.ScopedValue.get(ScopedValue.java:693)
at TestProviderLeak.main(TestProviderLeak.java:11)
at
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at
com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
at java.base/java.lang.Thread.run(Thread.java:1570)
```
- backported by
-
JDK-8320779 Unbound ScopedValue.get() throws the wrong exception
- Resolved