JDK-6964923 : Compiler incorrectly reports "incompatible types" with valid extended type param
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2010-06-29
  • Updated: 2012-03-20
  • Resolved: 2010-12-08
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)
OpenJDK Server VM (build 14.0-b16, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux btomasini-laptop 2.6.32-22-generic #36-Ubuntu SMP Thu Jun 3 22:02:19 UTC 2010 i686 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
The included code compiled just fine under JDK 6 but now fails under OpenJDK 6






EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected successful compilation
ACTUAL -
btomasini@btomasini-laptop:~$ javac Test.java
Test.java:12: incompatible types
found   : java.lang.Object
required: java.lang.String
	for (String string : newList(list)) {
	                            ^
1 error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;

public class Test
{

    public void test()
    {
	List<String> list = new ArrayList<String>();

	for (String string : newList(list)) {
	}
    }

    private static <T, V extends T> List<T> newList(Collection<V> list)
    {
	return new ArrayList<T>(list);
    }


}
---------- END SOURCE ----------

Comments
EVALUATION This should be fixed - either add for-each as assignment context considered by 15.12.2.8 or tweak 15.12.2.7 so that multiple dependent constraints are also taken into account.
01-12-2010