Community
Participate
Working Groups
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!
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.
Added AnnotationTest#test241
Created attachment 83312 [details] Zipped project demonstrating problem. pings folder has some possibly useful screen shots.
Reopening
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)
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.
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.
Ditto for don't warn about unused @SuppressWarnings("nls") if NLS warnings ignored. [MDT OCL is now emitting @SuppressWarnings("nls") into generated extensible code.]
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.
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.
Fixed the bug title to better reflect the present issue here.
Created attachment 83446 [details] Proposed patch
Added AnnotationTest#test243-246
Released for 3.4M4. Fixed
Verified for 3.4M4 using build I20071210-1800.