JDK-6302214 : erroneus "inconvertible types" error
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2005-07-26
  • Updated: 2010-04-02
  • Resolved: 2005-09-26
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
Upon compiling the given test case, javac complains as follows:
C:\A.java:5: inconvertible types
found   : X<capture of ? extends java.lang.Object>
required: X2
      m3((X2) m());
               ^
1 error

I originally thought it was an eclipse bug but there are compelling arguements to say that it should compile with a warning instead. For details please read the eclipse bug report:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=86898


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Save the code as A.java
2. javac A.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
compilation should work and there should only be a warning stating that the case is unsafe
ACTUAL -
compiler error
C:\eclipse\workspace\Scratch\src\A.java:5: inconvertible types
found   : X<capture of ? extends java.lang.Object>
required: X2
      m3((X2) m());
               ^
1 error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class B extends A<Object>
{
   void m2()
   {
      m3((X2) m());
   }
   
   void m3(X2 i)
   {
      
   }
}
public class A<T>
{
   X<? extends T> m()
   {
      return null;
   }
   
}

class X2 extends X<String>
{
   
}

class X<T>
{
   
}

---------- END SOURCE ----------

Comments
EVALUATION This bug reduces to this problem: class X<T> {} class X2 extends X<String> {} class Test { X<? extends Object> x; X2 x2 = (X2)x; }
27-07-2005