Community
Participate
Working Groups
The new specs say "Compilers are encouraged to issue warnings when this annotation type is applied to a method or constructor declaration where: - The variable-arity parameter has a reifiable element type, which includes primitive types, Object, and String. (The unchecked warnings this annotation type suppresses already do not occur for a reifiable element type.) - The body of the method or constructor declaration performs potentially unsafe operations, such as an assignment to an element of the variable-arity parameter's array that generates an unchecked warning. Future versions of the platform may mandate compiler errors for such unsafe operations. " So, it'll be good to introduce compiler warnings for usage of @SafeVarargs in following cases (1) class SafeVar { @SafeVarargs // TODO: warn here // reifiable variable arity parameter type public static <T> List<T> asList( T abc, Object... a) { return null; } } (2) class SafeVar { @SafeVarargs // TODO: warn here public static <T> List<T> asList( Object abc, T... a) { if (a.length == 1) { a[0] = (T) abc; // unchecked operation } return null; } }
See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=349669
Please implement the "varargs" suppression token to enable any new additional warnings to be suppressed when this is implemented.
See bug 349669 comment 10 for another interesting warning given by javac that is not currently reported by ECJ.
I'm using neon now and I still run into this problem when using Oracle's javac (1.8/102) on Windows 7 Having a pice of code like this private ICacheKey<T>[] subCaches; public SimpleCacheKey(final Comparator<T> comparator, final ICacheKey<T>... subCaches) { ... this.subCaches = subCaches; } Leads to the well known heap pollution warning. Adding annotation private ICacheKey<T>[] subCaches; @SafeVarargs public SimpleCacheKey(final Comparator<T> comparator, final ICacheKey<T>... subCaches) { ... this.subCaches = subCaches; } makes the warning disappear in Eclipse. But Oracle's javac now issues a warning for the line this.subCaches = subCaches; Oracle's javax warning can be suppresses by another annotation private ICacheKey<T>[] subCaches; @SafeVarargs @SuppressWarnings( "varargs" ) public SimpleCacheKey(final Comparator<T> comparator, final ICacheKey<T>... subCaches) { ... this.subCaches = subCaches; } but now Eclipse reports "Unsupported @SuppressWarnings("varargs")" Oracle's javac accepts this annotation and does no longer report any warnings but Eclise says that it's unsupported. Why?
(In reply to Stefan Lindner from comment #4) > Oracle's javac accepts this annotation and does no longer report any > warnings but Eclise says that it's unsupported. > > Why? Looks like we neither warn on incorrect usage of @SafeVarargs (which is what this bug is about) nor recognize "varargs" as a valid case for @SuppressWarnings.
bulk move out of 4.8