Bug 304031

Summary: Unused @SuppressWarnings(..) not flagged when suppressed problem is set to Error
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann, stephan.herrmann
Version: 3.6   
Target Milestone: 3.6 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix + regression tests
none
Proposed fix + regression tests
none
Proposed fix + regression tests none

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.