Community
Participate
Working Groups
The following program is supposed to elicit two compiler errors on the application of the SafeVarargs annotation to (a) a non varargs method (b) a non final instance method. javac correctly complains on these while eclipse fails to. import java.util.List; public class X { @SafeVarargs public static <T> List<T> asList() { // Error, not varargs return null; } @SafeVarargs public <T> List<T> asList2(T ... a) { // error not static or final return null; } @SafeVarargs public static <T> List<T> asList3(T ... a) { // OK, varargs & static return null; } @SafeVarargs public final <T> List<T> asList4(T ... a) { // OK varargs & final return null; } @SafeVarargs public final static <T> List<T> asList5(T ... a) { // OK, varargs & static & final return null; } }
Created attachment 189480 [details] Patch under test
Created attachment 189497 [details] Revised patch. This revised patch - extends the treatment to constructors also. - massages an existing test case that was "failing" due to expected output differing due to new IProblem introduction. - Adds suitable copyright message - Adds more tests - Passes all tests
Released the patch on the BETA_JAVA7 branch.
Resolved.
Verified.
On the subject of the @SafeVarArgs on non-final instance methods: I get the error (b) from comment 0 on a method in a final class (which happens to be a static nested class) that is not, itself, declared as final because that would be redundant. All methods of a final class are effectively final, so why is this error presented on the "add(...)" method below? public static final class ImmutableEListBuilder<E> { // ... @SafeVarargs public ImmutableEListBuilder<E> add(E element1, E element2, E element3, E element4, E... elements) { // ... }