Bug 252120 - [1.5][compiler] raw type diagnostic not coherent with javac one
Summary: [1.5][compiler] raw type diagnostic not coherent with javac one
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.5 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-26 16:00 EDT by Rémi Forax CLA
Modified: 2009-07-17 10:07 EDT (History)
3 users (show)

See Also:


Attachments
Proposed patch (18.22 KB, patch)
2008-11-03 08:12 EST, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rémi Forax CLA 2008-10-26 16:00:50 EDT
Build ID: I20080617-2000

Steps To Reproduce:
javac (1.7) generates a warning in that case :
class A<T> {
  void f() {
    boolean b=null instanceof A; 
  }
}


More information:
Recently, Maurizio Cimadamore adds a new warning to javac
that diagnoses usage of raw types.
http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types

Eclipse already do that for a while but
javac raises a warning in case of
instanceof using a raw type and not eclipse.
Comment 1 Philipe Mulet CLA 2008-10-27 05:58:22 EDT
Eclipse compiler explicitly doesn't report any warning for:
- class literal
- instanceof
- cast

Need to find out why I did disable these patterns previously.
Comment 2 Philipe Mulet CLA 2008-11-03 07:18:01 EST
Ignore previous comment re:cast. This is already implemented.
Class literal is also not diagnosed, since A<?>.class is not syntactically correct.

Added GenericTypeTest#test1398-1403
Comment 3 Philipe Mulet CLA 2008-11-03 08:12:25 EST
Created attachment 116806 [details]
Proposed patch
Comment 4 Philipe Mulet CLA 2008-11-04 05:02:59 EST
Released for 3.5M4
Fixed
Comment 5 Jerome Lanneluc CLA 2008-12-09 05:02:33 EST
Verified for 3.5M4 using I20081209-0100
Comment 6 Joerg Hohwiller CLA 2009-06-25 15:00:41 EDT
What have you done?
Could you please explain why you start begging everybody if he does
some "o instanceof Class" rather than "o instanceof Class<?>" ?
I can NOT see any particular use in this warning.
It is just totally nasty!
What do I miss here?
Comment 7 Rémi Forax CLA 2009-06-28 15:03:48 EDT
(In reply to comment #6)
> What have you done?
> Could you please explain why you start begging everybody if he does
> some "o instanceof Class" rather than "o instanceof Class<?>" ?
> I can NOT see any particular use in this warning.
> It is just totally nasty!
> What do I miss here?
> 

The answer is in the comments of this blog:
http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types

Rémi Forax
Comment 8 Joerg Hohwiller CLA 2009-07-03 11:25:07 EDT
Thanks for the hint. Still I do not agree and in the discussions there where arguments against it. Anyways I might not reopen the discussion here.
I just wanted to add a clear statement, that some eclipse-guyz made a decision here that I do NOT like and IMHO I guess that there are many others out there.
It is already hard to make developers care about warnings and not tend to add @SuppressWarnings("unchecked") everywhere. You gave those developers new dogfood.
Please note that refactoring operations that change the number of generic arguments break code if references get generified with wildcards so it is not always the best choice.
Comment 9 Joerg Hohwiller CLA 2009-07-03 16:09:03 EDT
There is no way to do something like
(object instanceof Class<String>) because of the erasure.
Therefore I can only do
(object instanceof Class) or (object instanceof Class<?>).
Both expressions are semantically equivalent.

Why should you raise a warning for the variant that people 
got used to over many years and that is absolutely harmless.
Should millions of users rewrite their code to avoid your 
new warnings?

I was already annoyed by all the abstract serializable classes
where I had to generate UIDs for to avoid warnings in new 
eclipse versions but at least I could see a point in doing this.
In this case this is pointless effort and I have tons of new warnings.
Comment 10 Joerg Hohwiller CLA 2009-07-03 16:14:32 EDT
Maybe I should apologize that I expressed my anger directly.
After all I thank you for Eclipse which is probably the best IDE.
If in the future a similar decision is made, I would be very pleased if you
consider to add an option for downward compatible behavior.
Maybe you might even think about adding such option for instanceof on raw types.
Thanks.
Comment 11 Stefan Baramov CLA 2009-07-17 09:26:45 EDT
I completely agree Jörg. He makes a very good point and it is a pity the bug is not fixed in 3.5 final. Which brings us to a good point, why is this bug marked as fixed any way? Target milestone 3.5 M4 ? 
Comment 12 Stefan Baramov CLA 2009-07-17 10:07:45 EDT
Please, disregard my last question. I was mislead by some of the previous comments.