# HG changeset patch # User alanb # Date 1304930825 25200 # Node ID efa758101257e4129641e34ee9bb48ce4b0d2542 # Parent 61242d00821f202520be65e0d0eeab3c95dc04dc# Parent 2d4eeef2bea2405f64c2baf8139e8af75376c8e9 Merge diff -r 2d4eeef2bea2 -r efa758101257 jdk/src/share/classes/java/lang/SafeVarargs.java --- a/jdk/src/share/classes/java/lang/SafeVarargs.java Tue May 03 22:16:58 2011 -0700 +++ b/jdk/src/share/classes/java/lang/SafeVarargs.java Mon May 09 01:47:05 2011 -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.