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

Sealed check for casts isn't applied to array components

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 20
    • 18
    • tools
    • None
    • b21

    Description

      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)

      Attachments

        Issue Links

          Activity

            People

              jlahoda Jan Lahoda
              dlsmith Dan Smith
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: