Sealed check for casts isn't applied to array components

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 20
    • Affects Version/s: 18
    • Component/s: tools
    • None
    • b21

      Casts to a sealed class check that the input type is castable to one of the permitted subclasses (which may themselves be sealed or final). When casting from one array type to another, the same check should be performed for a cast between the component types.

      sealed class A permits B, C {}
      class B extends A {}
      class C extends A {}

      jshell> (A) (Runnable) null // compiler error
      | Error:
      | incompatible types: java.lang.Runnable cannot be converted to A
      | (A) (Runnable) null
      | ^-------------^

      jshell> (A[]) new Runnable[5] // no compiler error
      | Exception java.lang.ClassCastException: class [Ljava.lang.Runnable; cannot be cast to class [LREPL.$JShell$17B$A; ([Ljava.lang.Runnable; is in module java.base of loader 'bootstrap'; [LREPL.$JShell$17B$A; is in unnamed module of loader jdk.jshell.execution.DefaultLoaderDelegate$RemoteClassLoader @3764951d)

            Assignee:
            Jan Lahoda
            Reporter:
            Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: