Bug 302467 - [1.5][compiler] Eclipse compiler fails with <?> generics
Summary: [1.5][compiler] Eclipse compiler fails with <?> generics
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2010-02-10 12:49 EST by Christophe Fondacci CLA
Modified: 2010-03-08 09:15 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christophe Fondacci CLA 2010-02-10 12:49:29 EST
Build Identifier: 20090621-0832

2 captures of a same class parametized with <?> raise a compilation error under Eclipse but compile OK with javac.

This is not a big problem, but it has already happen many times and is a bit annoying. A workaround is to remove the generic and to cast it to the "ungeneralized" class and to add a suppressWarning to avoid a compilation warning.


Reproducible: Always

Steps to Reproduce:
1. Create the following interfaces
public interface Task<T> {
  Collection<TaskListener<T>> getListeners();
}
public interface TaskListener<T> {
} 
2. Now in a new class, try the following code :
for (final Task<?> task : tasks) {
    for (final TaskListener<?> listener : task.getTaskListeners()) {
        // Following code raise a compilation error :
        // he method taskFailed(Task<capture#12-of ?>) in the type TaskListener<capture#12-of ?> is not applicable for the arguments (Task<capture#13-of ?>)
        listener.taskFailed(task, e);
    }
}
3. Try to compile it with javac: it works
Comment 1 Olivier Thomann CLA 2010-02-10 12:59:13 EST
Please attach a code snippet that shows the problem.
In the comment 0, 'e' is not defined. The listener interface doesn't define any method.
Thanks.
Comment 2 Srikanth Sankaran CLA 2010-02-19 05:39:36 EST
Hello Christophe,

Per comment#1 can you post a small but full program that shows the
problem ? As it is, we can make no progress whatsoever and will
have to close this as WORKSFORME.
Comment 3 Srikanth Sankaran CLA 2010-02-19 05:48:55 EST
The following program elicits a very similar warning from eclipse,
but it also gets the same warning from javac5,6,7.


import java.util.Collection;
interface Task<T> {
	Collection<TaskListener<T>> getTaskListeners();
}
interface TaskListener<T> {
	void taskFailed(Task<T> task);
} 
public class Test {
	public void driver(Collection<Task<?>> tasks){
		for (final Task<?> task : tasks) {
			for (final TaskListener<?> listener : task.getTaskListeners()) {
				listener.taskFailed(task);
			}
		}
	}
}
Comment 4 Srikanth Sankaran CLA 2010-02-25 00:04:06 EST
Please reopen if a test case becomes available. The posted incomplete
code snippet when "reasonably" completed via quick fixes results in
code which is treated identically by eclipse as by javac as shown
by comment#3
Comment 5 Ayushman Jain CLA 2010-03-08 07:45:32 EST
Verified for 3.6M6 using build I20100305-1011.
Comment 6 Jay Arthanareeswaran CLA 2010-03-08 08:28:10 EST
Verified
Comment 7 Christophe Fondacci CLA 2010-03-08 09:15:31 EST
Sorry, back from holidays...
While trying to extract a small test case I was not able to reproduce this problem either. This must be related to a specific use case. 
As soon as I reproduce it, I will re-open it. Until then, keeping it closed is fine.

Sorry for the lack of feedbacks