Bug 259378 - [1.5][compiler] Incorrect instanceof 'is a raw type' warning in 3.5M4
Summary: [1.5][compiler] Incorrect instanceof 'is a raw type' warning in 3.5M4
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-19 10:03 EST by Ed Willink CLA
Modified: 2009-07-23 10:09 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Willink CLA 2008-12-19 10:03:48 EST
In 3.5M4, the following snippet

public class XX<T> {

	public void g(Object o) {
		if (o instanceof XX)
			o = null;
	}
}

reports the use of instanceof XX as inappropriate.

In 3.5M3 no warning was issued.

Since type arguments cannot be checked, requiring the
rewrite to instanceof XX<?> seems very draconian and 
a major regression on a great deal of existing code.
Comment 1 Philipe Mulet CLA 2009-01-06 07:59:26 EST
This is consistent with javac 7 and described at: http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types

I agree it is annoying, but at the same time by using XX<?> you make it clear that you didn't miss the fact it was a generic type.
Comment 2 Ed Willink CLA 2009-01-10 03:39:28 EST
Ok. I guess that one day we'll learn to love this change.

In the meantime, with so many formerly warning-free plug-ins now averaging 10 warnings per plug-in, surely yet another selective enable/disable warning option is required in the project/workspace preferences? e.g. a sub-warning of the generic types warning to control warnings on instanceof similar to the sub-warnings for deprecations.
Comment 3 Mauro Molinari CLA 2009-07-23 10:09:19 EDT
(In reply to comment #1)
> This is consistent with javac 7 and described at:
> http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types
> 
> I agree it is annoying, but at the same time by using XX<?> you make it clear
> that you didn't miss the fact it was a generic type.

I do not agree with that. "o instanceof XX" is a test regarding the runtime type of o, which has nothing to do with generics! Moreover, maybe I have not read the document you mention enough deeply, however I read:

boolean b = o instanceof List; //same as o instanceof List<?>

which sounds to me that "o instanceof List" is the same as "o instanceof List<?>". Apart from the fact that "o instanceof List<?>" sounds quite an "error" to me, however if the two syntaxes are the same, why to issue a warning for the first?

At least I think the developer should be given the oportunity to disable this annoying (and useless! What's it useful for?) warning!