Bug 304031 - Unused @SuppressWarnings(..) not flagged when suppressed problem is set to Error
Summary: Unused @SuppressWarnings(..) not flagged when suppressed problem is set to Error
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 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-26 09:35 EST by Markus Keller CLA
Modified: 2010-03-09 05:00 EST (History)
2 users (show)

See Also:


Attachments
Proposed fix + regression tests (12.06 KB, patch)
2010-02-26 11:43 EST, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression tests (13.20 KB, patch)
2010-02-26 11:49 EST, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression tests (16.75 KB, patch)
2010-02-26 13:34 EST, 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 Markus Keller CLA 2010-02-26 09:35:17 EST
HEAD with fixes for bug 295551 and bug 303945

package xy;

public class TestUnused {
	void m() {
		@SuppressWarnings("cast")
		int i= (int) 0;
		@SuppressWarnings("cast")
		byte b= (byte) i;
		System.out.println(b);
	}
}

- set "Errors/Warnings > Unnecessary Code > Unnecessary cast or..." to Warning
=> second '@SuppressWarnings("cast")' has a warning:
  'Unnecessary @SuppressWarnings("cast")'. That's good.

- check "Errors/Warnings > Annotations > "Suppress optional errors with '@SuppressWarnings'"
=> warning stays (good)

- set "Errors/Warnings > Unnecessary Code > Unnecessary cast or..." to Error
=> warning on second annotation goes away (should stay)
Comment 1 Olivier Thomann CLA 2010-02-26 11:43:34 EST
Created attachment 160333 [details]
Proposed fix + regression tests

Running all tests to make sure we don't have regressions.
We had a check to tolerate unnecessary @SuppressWarnings when errors. This should only apply to mandatory errors.
Comment 2 Olivier Thomann CLA 2010-02-26 11:49:38 EST
Created attachment 160334 [details]
Proposed fix + regression tests

One more regression test.
Comment 3 Olivier Thomann CLA 2010-02-26 13:17:56 EST
This means that @SuppressWarnings are reported as unused if the corresponding setting is set to error and the new option is not set.

So that code:
public class TestUnused {
    void m() {
        @SuppressWarnings("cast")
        int i= (int) 0;
        @SuppressWarnings("cast")
        byte b= (byte) i;
        System.out.println(b);
    }
}

with:
- set "Errors/Warnings > Unnecessary Code > Unnecessary cast or..." to Error
- uncheck "Errors/Warnings > Annotations > "Suppress optional errors with
'@SuppressWarnings'"

both @SuppressWarnings are reported as unused.

Is this what you expect ?
Comment 4 Markus Keller CLA 2010-02-26 13:31:40 EST
(In reply to comment #3)
Yes, that would be fine with me.
Comment 5 Olivier Thomann CLA 2010-02-26 13:34:29 EST
Created attachment 160347 [details]
Proposed fix + regression tests

Updated existing tests.
Comment 6 Olivier Thomann CLA 2010-02-26 13:36:13 EST
Released for 3.6M6.
Regression tests added in:
org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test284
org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test285
org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test286
Comment 7 Frederic Fusier CLA 2010-03-09 05:00:42 EST
Verified for 3.6M6 using build I20100307-2000.