Bug 416276 - [generics][compiler] Unchecked invocation warning message mentions wrong raw type
Summary: [generics][compiler] Unchecked invocation warning message mentions wrong raw ...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-30 18:02 EDT by Robert Papp CLA
Modified: 2013-08-30 18:02 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 Robert Papp CLA 2013-08-30 18:02:55 EDT
public abstract class GenericWarningTest {
	abstract <T extends Comparable<T>> java.util.Iterator<T> give(T obj);
	abstract <T> void receive(T obj, java.util.Iterator<T> it);
	void testMethod() {
// Warning at next line:
// Type safety: Unchecked invocation receive(Baad, Iterator) of the generic method receive(T, Iterator<T>) of type GenericWarningTest
		receive(new Baad(), give(new Baad()));
		receive(new Good(), give(new Good()));
	}
}

@SuppressWarnings("rawtypes")
class Baad implements Comparable {
	@Override
	public int compareTo(Object o) {
		return 0;
	}
}
class Good implements Comparable<Good> {
	public int compareTo(Good o) {
		return 0;
	}
}

Iterator is parametrized everywhere, but the warning still states it's raw. However there's no mention of Comparable, the real bad guy here.

http://mindprod.com/jgloss/compileerrormessages.html clearly states what the problem is and http://stackoverflow.com/questions/15501884/java-generics-warnings-on-java-util-collections provides a solution, but I still think it would be nice if the compiler at least mentioned the part of the type being unsafe (Comparable in these cases).

By the way the origin of this came from Joda VS Mockito, the above is a minimal repro; for more see https://sourceforge.net/p/joda-time/bugs/172/ . Also if you investigate the hierarchy of Joda DateTime you can see it's not trivial to find the raw Comparable implements and associate it with the warning.