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

Compile-time error during casting array to intersection

    Details

    • Subcomponent:
    • Resolved In Build:
      b112
    • Verification:
      Verified

      Description

      The spec (jck8-jsr335-0.6.2) says:

      "If S is an array type SC[], that is, an array of components of type SC:[jls-5.5.1-600]
          - If T is an intersection type, T1 & ... & Tn, then it is a compile-time error if there exists a Ti (1 <= i <= n) such that S cannot be cast to Ti by this algorithm. [jsr335-5.5.1-600-E]"

      Actual behavior doesn't conforms the spec: check the following case:

      Object obj1 = (Integer[]) new Integer[1];

      Object obj2 = (Serializable) new Integer[1];

      no compile-time errors appear in that case. Following above-mentioned assertion It's legal to use casting array to intersection:

      Object obj3 = (Integer[] & Serializable)new Integer[1];

      it doesn't work and the compile-time error appears:

          java: unexpected type
          required: class
          found: java.lang.Integer[]


      The following JCK tests fail due to this issue:

      lang/LMBD/lmbd118/lmbd11803m341/lmbd11803m341.html
      lang/LMBD/lmbd118/lmbd11803m3/lmbd11803m3.html
      lang/LMBD/lmbd118/lmbd11803m141/lmbd11803m141.html
      lang/LMBD/lmbd118/lmbd11803m0/lmbd11803m0.html

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                emc Eric Mccorkle
                Reporter:
                ostrizhe Olga Strizhenko (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: