Bug 210213 - [1.5][compiler] Unused SuppressWarnings shouldn't complain if warnings are not even enabled
Summary: [1.5][compiler] Unused SuppressWarnings shouldn't complain if warnings are no...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-18 14:17 EST by Ed Willink CLA
Modified: 2007-12-11 11:28 EST (History)
2 users (show)

See Also:


Attachments
Zipped project demonstrating problem. (52.34 KB, application/octet-stream)
2007-11-20 03:41 EST, Ed Willink CLA
no flags Details
Proposed patch (11.90 KB, patch)
2007-11-21 12:11 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 Ed Willink CLA 2007-11-18 14:17:20 EST
I use the following method to perform the most outrageous casts and avoid the suppress warnings message on a line by line basis.

	@SuppressWarnings("unchecked")
	public static <T> T asClassUnchecked(Object object, T requiredClassObject) {
		return (T) object;
	}

typically as in

      asClassUnchecked(xx, (Xyzzy[])null);

3.4M3 reports the @SuppressWarnings("unchecked") as unnecessary!
Comment 1 Philipe Mulet CLA 2007-11-19 05:09:56 EST
Cannot reproduce. The following program produces no unnecessary @SuppressWarnings("unchecked"), as one would expect:

public class X {

	@SuppressWarnings("unchecked")
	public static <T> T asClassUnchecked(Object object, T requiredClassObject) {
		return (T) object;
	}
	public static void main(String... args) {
		X[] xs = X.asClassUnchecked("abc", (X[])null);
	}
}

Closing as invalid. Please reopen if you can provide better steps to reproduce.
Comment 2 Philipe Mulet CLA 2007-11-19 05:16:40 EST
Added AnnotationTest#test241
Comment 3 Ed Willink CLA 2007-11-20 03:41:23 EST
Created attachment 83312 [details]
Zipped project demonstrating problem. 

pings folder has some possibly useful screen shots.
Comment 4 Ed Willink CLA 2007-11-20 03:42:48 EST
Reopening
Comment 5 Philipe Mulet CLA 2007-11-20 06:58:44 EST
Did you enable unchecked warnings to be reported ? If not, then the @SuppressWarnings is indeed not used (since not suppressing actual warnings).

Pls check that these 2 options are activated:

Java>Compiler>Errors/Warnings>Generic types>Unchecked generic type operation>Warning
Java>Compiler>Errors/Warnings>Generic types>Usage of a raw type>Warning

(the latter is optional, but recommended)
Comment 6 Ed Willink CLA 2007-11-20 07:53:27 EST
Well spotted. I had the generic checks off to suit some traditional plugins.

Perhaps worth a better warning diagnostic to help other users gradually adapting from compatibility-generics to genuine-generics.

e.g.

Unnecessary @SuppressWarnings("unchecked"): generic type operation checking ignored

with a QuickFix to correct the compiler preferences.
Comment 7 Philipe Mulet CLA 2007-11-20 08:04:36 EST
Thinking more of it, maybe the unused suppressWarning should only be emmitted if compiler preferences allow these kinds of warnings only (i.e. if proven that enabled, and no trace of the warning). Need to see if easily doable.
Comment 8 Ed Willink CLA 2007-11-20 08:31:47 EST
Ditto for don't warn about unused @SuppressWarnings("nls") if NLS warnings ignored.

[MDT OCL is now emitting @SuppressWarnings("nls") into generated extensible code.]
Comment 9 Ed Willink CLA 2007-11-20 11:26:07 EST
Ditto hiding.

--------

Reopening: there really is a problem with generic casts.

The following (from org.eclipse.ocl.parser.AbstractOCLAnalyzer).

	protected OCLExpression<C> getLoopBody(OCLExpression<C> expr) {
		return ((LoopExp<C, PM>) expr).getBody();
	}

needs an @SuppressWarnings("unchecked") with Eclipse 3.3.1.

3.4M3 reports the cast as unnecessary. Not so.

The LoopExp is run-time checked.

The <C,?> is ok if the above check is ok since LoopExp<C,?> extends OCLExpression<C> - rather powerful and nice that you can now do this.

The <?,PM> cannot be checked since getBody is an interface method, so it is not
possible to prove that all implementations of getBody() are independent of the unconstrained PM type.
 
Comment 10 Philipe Mulet CLA 2007-11-20 12:02:40 EST
This is a different issue, so please file a different problem report, with all steps to reproduce. Be aware that between 3.3 and 3.4, considerable refinements got introduced near unchecked cast warnings.
Comment 11 Philipe Mulet CLA 2007-11-21 12:10:30 EST
Fixed the bug title to better reflect the present issue here.
Comment 12 Philipe Mulet CLA 2007-11-21 12:11:16 EST
Created attachment 83446 [details]
Proposed patch
Comment 13 Philipe Mulet CLA 2007-11-21 12:19:39 EST
Added AnnotationTest#test243-246
Comment 14 Philipe Mulet CLA 2007-11-21 12:58:11 EST
Released for 3.4M4.
Fixed
Comment 15 Kent Johnson CLA 2007-12-11 11:28:13 EST
Verified for 3.4M4 using build I20071210-1800.