Bug 91017

Summary: [1.5] [compiler] eclipse compiler accepts method call with unbound type wildcard ('?') that is flagged as error by jdk
Product: [Eclipse Project] JDT Reporter: Matt McHenry <eclipse>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED DUPLICATE QA Contact:
Severity: critical    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M7   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Matt McHenry CLA 2005-04-11 12:39:00 EDT
This might be a duplicate of bug 84496, but I'm rather new to generics so I'm
not sure.  In the code snippet below, the indicated line generates the following
error when compiled with sun's javac:

cannot find symbol
 symbol  : method addAll(java.util.List<capture of ?>)
 location: interface java.util.List<capture of ?>
 untypedList.addAll(untypedList2);

But with eclipse's compiler (3.1M6), it is not flagged as an error.  And when
the code runs, it generates a ClassCastException.

----

import java.util.ArrayList;
import java.util.List;

public class Test_Lists {
	public static void main(String[] args) {
		List<String> stringList = new ArrayList<String>();
		stringList.add("foo");
		List<Integer> intList = new ArrayList<Integer>();
		intList.add(1);

		List<?> untypedList = stringList;
		List<?> untypedList2 = intList;

		//correctly flagged as error: untypedList.add(new Object());
		//ditto: untypedList.add(untypedList2.get(0));

		//but this is not flagged at all by eclipse:
		untypedList.addAll(untypedList2);

		for(String s : stringList){
			//next line generates runtime ClassCastException
			Logger.log("Test_Lists.main: s: " + s);
		}
	}
}
Comment 1 Philipe Mulet CLA 2005-04-11 15:02:08 EDT
Added GenericTypeTest#test584.
This is indeed a dup.
Comment 2 Philipe Mulet CLA 2005-04-11 15:02:33 EDT

*** This bug has been marked as a duplicate of 84495 ***
Comment 3 Philipe Mulet CLA 2005-04-11 15:02:56 EDT
oops, wrong dup bug number
Comment 4 Philipe Mulet CLA 2005-04-11 15:03:16 EDT

*** This bug has been marked as a duplicate of 84496 ***