Bug 91017 - [1.5] [compiler] eclipse compiler accepts method call with unbound type wildcard ('?') that is flagged as error by jdk
Summary: [1.5] [compiler] eclipse compiler accepts method call with unbound type wildc...
Status: RESOLVED DUPLICATE of bug 84496
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 critical (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-11 12:38 EDT by Matt McHenry CLA
Modified: 2005-04-11 15:03 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***