JDK-6211853 : "unchecked" warning for checked cast
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-12-22
  • Updated: 2010-04-02
  • Resolved: 2005-09-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6Resolved
Related Reports
Duplicate :  
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

Comments
EVALUATION Yes, this is a bug. We should try to address this for mustang and consider backporting to JDK 5.0. ###@###.### 2005-1-26 20:07:28 GMT
26-01-2005