Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8319120

Unbound ScopedValue.get() throws the wrong exception

    XMLWordPrintable

Details

    • b22
    • generic
    • Verified

    Backports

      Description

        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)
        ```

        Attachments

          Issue Links

            Activity

              People

                aph Andrew Haley
                aph Andrew Haley
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: