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

"unchecked" warning for checked cast

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

      java version "1.5.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
      Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]
      (Japanese)

      A DESCRIPTION OF THE PROBLEM :
      The following Test.java is warned but it should not be warned.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      >javac -J-Duser.language=en -version -Xlint:unchecked Test.java
      javac 1.5.0_01
      Test.java:8: warning: [unchecked] unchecked cast
      found : java.util.List<capture of ? extends java.lang.String>
      required: StringList
              java.util.List<String> b = (StringList) a; // warned but safe.
                                                      ^
      1 warning

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Test.java can be compiled without warnings.
      ACTUAL -
      A [unchecked] warning.
      (See "Steps to Reproduce")

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      --------Test.java--------
      class StringList extends java.util.LinkedList<String> {
      }

      public class Test {
          public static void main(String[] args) {
              java.util.List<? extends String> a = new StringList();
              java.util.List<String> b = (StringList) a; // warned but safe.
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use StringList.class.cast(a)
      ###@###.### 2004-12-22 18:38:01 GMT

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ahe Peter Ahe
                Reporter:
                rmandalasunw Ranjith Mandala (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: