Bug 290034 - Effects of @SuppressWarnings("unchecked") are broader in Eclipse than in javac
Summary: Effects of @SuppressWarnings("unchecked") are broader in Eclipse than in javac
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M3   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 253663 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-09-21 12:50 EDT by akrieg CLA
Modified: 2009-12-06 09:39 EST (History)
6 users (show)

See Also:


Attachments
Proposed fix + updated regression tests (5.50 KB, patch)
2009-09-22 14:03 EDT, Olivier Thomann CLA
no flags Details | Diff
Same patch that includes jdt.ui.tests patch (10.94 KB, patch)
2009-09-22 15:18 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + updated regression tests (14.51 KB, patch)
2009-09-23 12:57 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description akrieg CLA 2009-09-21 12:50:18 EDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Build Identifier: 20090619-0625

Eclipse seems to overload "unchecked" warning suppression to also suppress raw uses of parameterized classes.  Javac doesn't issue a warning in this case so there's nothing to suppress.  However this does pose an issue when working with other IDE's as they will complain about the use of a raw parameterized class.  The following snippet illustrates the difference:

public class Foo<T> {
    //This is unchecked assignment
    //and should be suppressed using "unchecked"
    //This will appear as a warning in javac
    Foo<T>[] a = new Foo[10];

    //This is raw use of a paramterized type
    //Not suppressed in javac using "unchecked"
    //This will NOT appear as a warning in javac
    Foo[] b = new Foo[10];
}

The workaround is to declare b with a wildcard, e.g.:

Foo<?>[] b = new Foo[10];

Reproducible: Always
Comment 1 Olivier Thomann CLA 2009-09-22 13:09:08 EDT
@SuppressWarnings("unchecked") is not documented to have any effect on raw type warnings.
We should add @SuppressWarnings("raw") for raw types warnings.
Comment 2 Olivier Thomann CLA 2009-09-22 14:03:26 EDT
Created attachment 147814 [details]
Proposed fix + updated regression tests
Comment 3 Olivier Thomann CLA 2009-09-22 15:09:21 EDT
Markus and Daniel, I believe we should split @SuppressWarnings("unchecked") into @SuppressWarnings("unchecked") and @SuppressWarnings("raw").
@SuppressWarnings("unchecked") would be reserved for unchecked warnings and @SuppressWarnings("raw") would be used only for raw type references.
Comment 4 Olivier Thomann CLA 2009-09-22 15:18:27 EDT
Created attachment 147827 [details]
Same patch that includes jdt.ui.tests patch
Comment 5 Olivier Thomann CLA 2009-09-22 15:34:58 EDT
Adding @SuppressWarnings("unchecked") on a class will hide all real unchecked warnings issues as well as raw warnings issues. People using a 1.5 framework might want to get rid of raw warnings, but "fix" all unchecked warnings.
If existing code has new warnings, then there is a quickfix for them or the warnings can be "fixed".
Comment 6 Markus Keller CLA 2009-09-22 16:15:57 EDT
(In reply to comment #3)
I would fully agree if this was the release in which we introduced "unchecked". 

The problem is that we supported "unchecked" for raw types for a long time,
(bug 89529 comment 9) and changing it now means that users need to update their
codebase. And if their team uses Eclipse 3.5 and 3.6, they can't even get a
clean table any more.

I wanted to suggest that we add "raw" now, but wait for 3.7 to stop accepting
them with "unchecked". But then I found that JDK7 will probably use
@SuppressWarnings("rawtypes") for that, see the link in bug 253663:
http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types
Comment 7 Markus Keller CLA 2009-09-22 16:16:10 EDT
*** Bug 253663 has been marked as a duplicate of this bug. ***
Comment 8 Olivier Thomann CLA 2009-09-22 17:21:10 EDT
I don't have any problem by using "rawtypes" instead of "raw" for the @SuppressWarnings token.
I understand that this might require users to add additional SuppressWarnings annotation, but changing it now will prevent them from doing it when the codebase is even bigger.
The sooner, the better.
Comment 9 Dani Megert CLA 2009-09-23 06:15:59 EDT
I agree with most that has been said so far i.e. we want to separate this but we also have to consider the migration path. Here's what Markus and I discussed would be a good path for 3.6:

- we no longer suppress raw when "unchecked" is used
- we introduce "rawtypes" for that
- we encourage people to fix their code
- for those that do not or cannot fix the additional warnings that they get we
  offer an environment variable that can be set on start up, e.g.
   -vmargs -DsuppressRawWhenUnchecked=true
- we will document this in the migration guide

Of course we will also have to adjust the UI code to this change.
Comment 10 Olivier Thomann CLA 2009-09-23 10:12:01 EDT
(In reply to comment #9)
> - we no longer suppress raw when "unchecked" is used
> - we introduce "rawtypes" for that
I'll update the patch for this. I used "raw" for now.

> - for those that do not or cannot fix the additional warnings that they get we
>   offer an environment variable that can be set on start up, e.g.
>    -vmargs -DsuppressRawWhenUnchecked=true
I don't see the point. Why would it be a problem to "fix" the additional warnings?
The UI provides a quickfix and the quickfix to add the @SuppressWarnings("rawtypes") works without any changes in the UI.
However I'll prepare a patch that contains this property. I just would like to understand what use case requires that property to be added.

> - we will document this in the migration guide
Good.

> Of course we will also have to adjust the UI code to this change.
The previous patch contained the changes for the UI tests. I'll update it as well to use "rawtypes" instead of "raw".
Comment 11 Dani Megert CLA 2009-09-23 10:19:49 EDT
>I don't see the point. Why would it be a problem to "fix" the additional
>warnings?
Two reasons:
1. some teams working on the same code might not be able to use the latest
   eclipse version (in this case even no final version yet) and if the warning
   is fixed in HEAD then those working with an older version will get a warning
   for unknown @suppressWarning tag.
2. some teams might might not have time to fix the warnings
Comment 12 Olivier Thomann CLA 2009-09-23 12:57:29 EDT
Created attachment 147902 [details]
Proposed fix + updated regression tests

Patch that addresses most of the points in comment 9.
>- we no longer suppress raw when "unchecked" is used
Done
>- we introduce "rawtypes" for that
Done
>- we encourage people to fix their code
Not done. I guess this is done in the migration guide.

>- for those that do not or cannot fix the additional warnings that they get we
>  offer an environment variable that can be set on start up, e.g.
>   -vmargs -DsuppressRawWhenUnchecked=true
Done.
>- we will document this in the migration guide
Not dome.

The migration guide will be updated separately.
Markus, could you please take care of releasing the jdt.ui.tests part of the patch?
Thanks.
Comment 13 Markus Keller CLA 2009-09-23 13:31:07 EDT
> Markus, could you please take care of releasing the jdt.ui.tests part of the
> patch?

Released, thanks for the patch.
Comment 14 Olivier Thomann CLA 2009-09-23 13:50:20 EDT
Released for 3.6M3.
Updated existing tests.
Comment 15 Dani Megert CLA 2009-09-24 03:22:11 EDT
Thanks for the quick fix. I've filed bug 290361 to track the JDT UI work.

>The migration guide will be updated separately.
Do you have a log for that somewhere? If not, it makes your life harder near the end of the release or you might miss an entry. Also, people using 3.6 builds might run into this and would be happy to get some information in the migration guide. I've prepared the JDT migration guide for 3.6.
Comment 16 Markus Keller CLA 2009-09-24 09:54:18 EDT
> >The migration guide will be updated separately.

The entry should also tell that projects need to be manually cleaned and rebuilt after toggling the property.
Comment 17 Ayushman Jain CLA 2009-10-27 07:03:45 EDT
Verified for 3.6M3 using build I20091025-2000.
Comment 18 Ralf Ebert CLA 2009-12-06 09:39:30 EST
Any chance to support @SuppressWarnings("rawtypes") in 3.5.2 to ease the adoption of the change and to make this less confusing when people are using 3.5 and 3.6 in parallel? If you write code in 3.6 now, developers using 3.5 get 
(imho) invalid warnings now:

Unsupported @SuppressWarnings("rawtypes")
Class is a raw type. References to generic type Class<T> should be parameterized