--- old/src/share/classes/java/lang/SafeVarargs.java 2011-05-06 17:04:44.000000000 -0700 +++ new/src/share/classes/java/lang/SafeVarargs.java 2011-05-06 17:04:44.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,7 +32,7 @@ * constructor does not perform potentially unsafe operations on its * varargs parameter. Applying this annotation to a method or * constructor suppresses unchecked warnings about a - * non-reifiable variable-arity (vararg) type and suppresses + * non-reifiable variable arity (vararg) type and suppresses * unchecked warnings about parameterized array creation at call * sites. * @@ -41,11 +41,10 @@ * additional usage restrictions on this annotation type; it is a * compile-time error if a method or constructor declaration is * annotated with a {@code @SafeVarargs} annotation, and either: - *
+ * + * leads to a {@code ClassCastException} at runtime. * *+ * @SafeVarargs // Not actually safe! + * static void m(List<String>... stringLists) { + * Object[] array = stringLists; + * List<Integer> tmpList = Arrays.asList(42); + * array[0] = tmpList; // Semantically invalid, but compiles without warnings + * String s = stringLists[0].get(0); // Oh no, ClassCastException at runtime! + * } + *
Future versions of the platform may mandate compiler errors for * such unsafe operations.