JDK-6452148 : wrong type checking with lower bounded wildcard
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: linux
  • CPU: x86
  • Submitted: 2006-07-24
  • Updated: 2010-07-29
  • Resolved: 2010-07-29
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Linux meco 2.6.10 #1 SMP Wed Aug 31 19:48:13 CEST 2005 i686 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
I have found javac to generate a compiler error for the generic type invocation in the below code even though I understand that the code is correct. The error produced claims that the wildcard type argument "? super C2" is not within the bound of the formal type parameter.

=== $ cat -n A.java
     1  interface I { }
     2  class C1 { }
     3  class C2 extends C1 implements I { }
     4
     5  public class A<T extends C1 & I> {
     6      A<? super C2> a;
     7  }

=== $ javac A.java
A.java:6: type parameter ? super C2 is not within its bound
    A<? super C2> a;
              ^
1 error

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Invoke the javac on the provided code file.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code snippet should compile without errors.
ACTUAL -
A compiler error is generated for the generic type invocation.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Compiler error produced by javac:

A.java:6: type parameter ? super C2 is not within its bound
    A<? super C2> a;
              ^
1 error


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
interface I { }
class C1 { }
class C2 extends C1 implements I { }

public class A<T extends C1 & I> {
    A<? super C2> a;
} 

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

Comments
EVALUATION The fix for this bug got integrated into fix for 6638712.
29-07-2010

EVALUATION This is caused by 6718388 (missing subtyping rules for intersection types): In fact, javac ends up in performing the following subtyping test: C2 <: C1 & I1 which should be true, since a) C2 <: C1 AND b) C2 <: I however JLS does not support this kind of subtyping yet.
13-03-2009

EVALUATION A bug since A<C2> would be fine.
16-10-2006