JDK-6466471 : assignment to array-lower bounded wildcard
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2006-09-01
  • Updated: 2011-02-16
  • Resolved: 2006-09-01
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
Java HotSpot(TM) Client VM (build 1.5.0_07-b03, 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 :
The following assignment to a lower bounded wildcard should compile without errors as the array is assignable to the wildcard capture's lower bound. Instead, javac produces the below compiler error.

Note that javac 1.6 does this correctly! However, if there still are release cycles for javac 1.5, it would be nice to also fix it there.

=== $ cat -n Bug1.java
     1  public class Bug1<T> {
     2          T t;
     3
     4          void foo() {
     5                  Bug1<? super Integer[]> a = null;
     6                  a.t = new Integer[0];
     7          }
     8  }

=== $ javac Bug1.java
  Bug1.java:6: incompatible types
found   : java.lang.Integer[]
required: capture of ? super java.lang.Integer[]
                a.t = new Integer[0];
                      ^
1 error

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the provided source file.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No compiler errors should be generated.
ACTUAL -
The assignment produces a compiler error.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
  Bug1.java:6: incompatible types
found   : java.lang.Integer[]
required: capture of ? super java.lang.Integer[]
                a.t = new Integer[0];
                      ^
1 error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Bug1<T> {
	T t;

	void foo() {
		Bug1<? super Integer[]> a = null;
		a.t = new Integer[0];
	}
}

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

CUSTOMER SUBMITTED WORKAROUND :
Use javac 1.6.