Bug 371832 - The preference "Suppress optional errors with '@SuppressWarnings'" ends up silencing warnings it shouldn't
Summary: The preference "Suppress optional errors with '@SuppressWarnings'" ends up si...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.8 M7   Edit
Assignee: Satyam Kandula CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 376390 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-02-16 19:15 EST by John Cortell CLA
Modified: 2012-04-30 05:24 EDT (History)
6 users (show)

See Also:
amj87.iitr: review+


Attachments
Patch under consideration (9.71 KB, patch)
2012-02-22 09:14 EST, Satyam Kandula CLA
no flags Details | Diff
Proposed patch (41.09 KB, patch)
2012-04-23 01:28 EDT, Satyam Kandula CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Cortell CLA 2012-02-16 19:15:04 EST
This preference was added a couple of years ago via bug 295551. It's been instrumental in keeping our code warning-free.

Unfortunately, we just came across a side-effect. It is causing 'unused import' warnings to be silenced in certain situations. This is happening in 3.8 and 4.2

Reproducibility steps:
1. Create Plug-in project (use all defaults)

2. In Activator.java do the following
   - add unused import statement for java.util.List
   - add import statement for internal type org.eclipse.ui.internal.util.Descriptors
   - Add @SuppressWarnings(“restriction”) right above the class declaration to silence the warning caused by the last step
At this point, the file should have two unused import warnings

3. Bring up the project properties and check “Enable project specific settings” in the Java Compiler > Errors/Warnings page

4. Change “Discouraged reference” from Warning to Error and do the same for “Suppress optional errors with ‘@SuppressWarnings’”

BUG: the unused import warnings go away. Note the only things we are suppressing with @SuppressWarnings are restriction issues.. The unused imports should continue to be flagged as a warning.
Comment 1 John Cortell CLA 2012-02-16 19:19:29 EST
Correction. Step (4) should read:

4. Change “Discouraged reference” from Warning to Error and *CHECK*
“Suppress optional errors with ‘@SuppressWarnings’”
Comment 2 Srikanth Sankaran CLA 2012-02-16 19:29:44 EST
Satyam, Please take a look. Thanks.
Comment 3 Satyam Kandula CLA 2012-02-22 08:27:50 EST
Checking for the 'unused imports' is being done at the end of the 'resolve'
stage and it is done only if the error count is 0. Suppressed errors are
removed from the error list only at the end of the compilation process.
In this case, the errors like 'forbidden reference' are found during the
'resolve' stage and hence the error count is not zero at the time of the check
of 'unused imports' causing this issue.

This could be fixed by using the 'non-suppressed' error count as this condition
for checking of 'unused imports'. As of now we don't have this number and we
can get this by looking if the error is suppressed while the error is being
added. We do that currently in some circumstances and we can probably extend
that now, but there is a small performance impact.

IMO we could just use 'non-optional' error count instead of 'non-suppressed'
error count for checking. 'non-optional' errors are the errors which cannot be
configured. There will not be a performance impact because of this and more
importantly I don't see any issue with this approach. 

I will post a patch shortly.
Comment 4 Satyam Kandula CLA 2012-02-22 09:14:31 EST
Created attachment 211404 [details]
Patch under consideration
Comment 5 Satyam Kandula CLA 2012-02-22 09:15:27 EST
Srikanth, Can you please review this?
Comment 6 Jay Arthanareeswaran CLA 2012-02-24 09:28:49 EST
Something is wrong. I see the changes already in master and may be causing some failures. I am going to revert the commit for now.
Comment 7 Satyam Kandula CLA 2012-02-24 10:36:23 EST
(In reply to comment #6)
> Something is wrong. I see the changes already in master and may be causing some
> failures. I am going to revert the commit for now.
Ooops, you are right. My workspace wasn't clean and I accidently released it along with another bug :(.
Comment 8 Satyam Kandula CLA 2012-02-24 10:40:28 EST
(In reply to comment #6)
> Something is wrong. I see the changes already in master and may be causing some
> failures. I am going to revert the commit for now.
I didn't see the revert. So, I reverted it.
Comment 9 Jay Arthanareeswaran CLA 2012-02-24 10:44:00 EST
(In reply to comment #8)
> I didn't see the revert. So, I reverted it.

I thought I would just run all tests once before pushing. Now that you have reverted, HEAD should be alright now.
Comment 10 Srikanth Sankaran CLA 2012-02-24 20:14:29 EST
Satyam, is the patch ready for review ? Comment#6 refers to some
failures.
Comment 11 Srikanth Sankaran CLA 2012-02-24 20:17:57 EST
Ayush, can you please review this when it is ready ?
Comment 12 Ayushman Jain CLA 2012-02-25 08:26:12 EST
(In reply to comment #11)
> Ayush, can you please review this when it is ready ?
Sure.
Comment 13 Satyam Kandula CLA 2012-02-27 00:37:49 EST
(In reply to comment #10)
> Satyam, is the patch ready for review ? Comment#6 refers to some
> failures.
Yes, there are test failures :(. 

These are caused by presence of 'resolve' errors in the javadoc. Without this patch, 'unused import' analysis wasn't being done if there are any errors. With this patch, presence of non-optional errors will only stop processing the 'unused import' analysis. As javadoc errors are optional, the import analysis is being done and these errors are causing the extra failures. 

IMHO, this is right behaviour, but I will have to investigate all the test failures  properly. I will update once I am done. 

Ayush, please wait until I update - Thanks.
Comment 14 Satyam Kandula CLA 2012-04-10 09:01:12 EDT
*** Bug 376390 has been marked as a duplicate of this bug. ***
Comment 15 Satyam Kandula CLA 2012-04-23 01:28:50 EDT
Created attachment 214363 [details]
Proposed patch

Patch after remastering the failed tests. They were javadoc tests which were failing. In all these cases they were import errors because of javadoc 'resolution' errors. I think it is better to get those errors in this cases. 

Ayush, please review this patch and let me know your comments.
Comment 16 Ayushman Jain CLA 2012-04-27 11:32:09 EDT
Patch looks good.

Note that now we do warn unused imports even when they're mandatory errors (Such as the case below).
import java.util.*;


public class E {

	@SuppressWarnings({ "null", "unused" })
	
	void foo(Object o) {
		int i;
		o = null;
		if (o == null) {
			i = 1 ;
			
		} 
		System.out.println(i);
	}
}

However, since these are discovered during analysis stage, i.e. after resolution stage, its ok to assume that everything is resolved and the import is indeed unused.
Comment 17 Satyam Kandula CLA 2012-04-28 02:00:25 EDT
Thanks Ayush for your review. 
Released the patch in master via commit d36a5b020e7b8fc57d912810db0ffb9dd045eb9a
Comment 18 Jay Arthanareeswaran CLA 2012-04-30 05:24:25 EDT
Verified for 3.8 M7 with build I20120429-1800