The pair of annotation types {@code @ContainedBy} and - * {@link java.lang.annotation.ContainerFor @ContainerFor} are used to - * indicate that annotation types are repeatable. Specifically: - * - *
- * An inconsistent pair of {@code @ContainedBy} and - * {@code @ContainerFor} annotations on a repeatable annotation type - * and its containing annotation type (JLS 9.6) will lead to - * compile-time errors and runtime exceptions when using reflection to - * read annotations of a repeatable type. - * - * @see java.lang.annotation.ContainerFor - * @since 1.8 - * @jls 9.6 Annotation Types - * @jls 9.7 Annotations - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.ANNOTATION_TYPE) -public @interface ContainedBy { - /** - * Indicates the containing annotation type for the - * repeatable annotation type. - */ - Class extends Annotation> value(); -} diff -r 4fed4c1bbc29 -r 685a9dff6458 jdk/src/share/classes/java/lang/annotation/ContainerFor.java --- a/jdk/src/share/classes/java/lang/annotation/ContainerFor.java Thu Jan 31 10:22:25 2013 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2012, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package java.lang.annotation; - -/** - * The annotation type {@code java.lang.annotation.ContainerFor} is - * used to indicate that the annotation type whose declaration it - * (meta-)annotates is a containing annotation type. The - * value of {@code @ContainerFor} indicates the repeatable - * annotation type for the containing annotation type. - * - *
The pair of annotation types {@link - * java.lang.annotation.ContainedBy @ContainedBy} and - * {@code @ContainerFor} are used to indicate that annotation types - * are repeatable. Specifically: - * - *
- * An inconsistent pair of {@code @ContainedBy} and - * {@code @ContainerFor} annotations on a repeatable annotation type - * and its containing annotation type (JLS 9.6) will lead to - * compile-time errors and runtime exceptions when using reflection to - * read annotations of a repeatable type. - * - * @see java.lang.annotation.ContainedBy - * @since 1.8 - * @jls 9.6 Annotation Types - * @jls 9.7 Annotations - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.ANNOTATION_TYPE) -public @interface ContainerFor { - - /** - * Indicates the repeatable annotation type for the containing - * annotation type. - */ - Class extends Annotation> value(); -} diff -r 4fed4c1bbc29 -r 685a9dff6458 jdk/src/share/classes/java/lang/annotation/InvalidContainerAnnotationError.java --- a/jdk/src/share/classes/java/lang/annotation/InvalidContainerAnnotationError.java Thu Jan 31 10:22:25 2013 -0800 +++ b/jdk/src/share/classes/java/lang/annotation/InvalidContainerAnnotationError.java Thu Jan 31 14:10:14 2013 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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 @@ -27,10 +27,9 @@ import java.util.Objects; /** - * Thrown to indicate that an annotation type whose declaration is - * (meta-)annotated with a {@link ContainerFor} annotation is not, in - * fact, the containing annotation type of the type named by {@link - * ContainerFor}. + * Thrown to indicate that an annotation type expected to act as a + * container for another annotation type by virture of an @Repeatable + * annotation, does not act as a container. * * @see java.lang.reflect.AnnotatedElement * @since 1.8 diff -r 4fed4c1bbc29 -r 685a9dff6458 jdk/src/share/classes/java/util/Base64.java --- a/jdk/src/share/classes/java/util/Base64.java Thu Jan 31 10:22:25 2013 -0800 +++ b/jdk/src/share/classes/java/util/Base64.java Thu Jan 31 14:10:14 2013 -0800 @@ -413,6 +413,7 @@ * specified Base64 encoded format */ public OutputStream wrap(OutputStream os) { + Objects.requireNonNull(os); return new EncOutputStream(os, isURL ? toBase64URL : toBase64, newline, linemax); } @@ -695,7 +696,7 @@ * using the {@link Base64} encoding scheme. * *
An invocation of this method has exactly the same effect as invoking
- * {@code return decode(src.getBytes(StandardCharsets.ISO_8859_1))}
+ * {@code decode(src.getBytes(StandardCharsets.ISO_8859_1))}
*
* @param src
* the string to decode
@@ -866,6 +867,7 @@
* byte stream
*/
public InputStream wrap(InputStream is) {
+ Objects.requireNonNull(is);
return new DecInputStream(is, isURL ? fromBase64URL : fromBase64, isMIME);
}
@@ -1012,9 +1014,12 @@
int len = sl - sp;
if (len == 0)
return 0;
- if (len < 2)
+ if (len < 2) {
+ if (isMIME && base64[0] == -1)
+ return 0;
throw new IllegalArgumentException(
"Input byte[] should at least have 2 bytes for base64 bytes");
+ }
if (src[sl - 1] == '=') {
paddings++;
if (src[sl - 2] == '=')
diff -r 4fed4c1bbc29 -r 685a9dff6458 jdk/test/java/lang/reflect/Parameter/WithoutParameters.java
--- a/jdk/test/java/lang/reflect/Parameter/WithoutParameters.java Thu Jan 31 10:22:25 2013 -0800
+++ b/jdk/test/java/lang/reflect/Parameter/WithoutParameters.java Thu Jan 31 14:10:14 2013 -0800
@@ -23,163 +23,152 @@
/*
* @test
+ * @bug 8004729
* @summary javac should generate method parameters correctly.
*/
import java.lang.*;
import java.lang.reflect.*;
+import java.lang.annotation.*;
import java.util.List;
+import java.util.Objects;
+
+import static java.lang.annotation.ElementType.*;
public class WithoutParameters {
+ int errors = 0;
- private static final Class>[] qux_types = {
- int.class,
- Foo.class,
- List.class,
- List.class,
- List.class,
- String[].class
- };
+ private WithoutParameters() {}
public static void main(String argv[]) throws Exception {
- int error = 0;
- Method[] methods = Foo.class.getMethods();
- for(Method m : methods) {
- System.err.println("Inspecting method " + m);
- Parameter[] parameters = m.getParameters();
- if(parameters == null)
- throw new Exception("getParameters should never be null");
- for(int i = 0; i < parameters.length; i++) {
- Parameter p = parameters[i];
- if(!p.getDeclaringExecutable().equals(m)) {
- System.err.println(p + ".getDeclaringExecutable != " + m);
- error++;
- }
- if(null == p.getType()) {
- System.err.println(p + ".getType() == null");
- error++;
- }
- if(null == p.getParameterizedType()) {
- System.err.println(p + ".getParameterizedType == null");
- error++;
- }
- }
- if(m.getName().equals("qux")) {
- if(6 != parameters.length) {
- System.err.println("Wrong number of parameters for qux");
- error++;
- }
- for(int i = 0; i < parameters.length; i++) {
- Parameter p = parameters[i];
- // The getType family work with or without
- // parameter attributes compiled in.
- if(!parameters[i].getType().equals(qux_types[i])) {
- System.err.println("Wrong parameter type for " + parameters[0] + ": expected " + qux_types[i] + ", but got " + parameters[i].getType());
- error++;
+ WithoutParameters wp = new WithoutParameters();
+ wp.runTests(Foo.class.getMethods());
+ wp.runTests(Foo.Inner.class.getConstructors());
+ wp.checkForErrors();
+ }
+
+ void runTests(Method[] methods) throws Exception {
+ for(Method m : methods) {runTest(m);}
+ }
+
+ void runTests(Constructor[] constructors) throws Exception {
+ for(Constructor c : constructors) {runTest(c);}
+ }
+
+ void runTest(Executable e) throws Exception {
+ System.err.println("Inspecting executable " + e);
+ Parameter[] parameters = e.getParameters();
+ Objects.requireNonNull(parameters, "getParameters should never be null");
+
+ ExpectedParameterInfo epi = e.getAnnotation(ExpectedParameterInfo.class);
+ if (epi != null) {
+ abortIfTrue(epi.parameterCount() != e.getParameterCount(), "Bad parameter count for "+ e);
+ abortIfTrue(epi.isVarArgs() != e.isVarArgs(),"Bad varargs value for "+ e);
+ }
+ abortIfTrue(e.getParameterCount() != parameters.length, "Mismatched of parameter counts.");
+
+ for(int i = 0; i < parameters.length; i++) {
+ Parameter p = parameters[i];
+ errorIfTrue(!p.getDeclaringExecutable().equals(e), p + ".getDeclaringExecutable != " + e);
+ Objects.requireNonNull(p.getType(), "getType() should not be null");
+ Objects.requireNonNull(p.getParameterizedType(), "getParameterizedType() should not be null");
+
+ if (epi != null) {
+ Class> expectedParameterType = epi.parameterTypes()[i];
+ errorIfTrue(!p.getType().equals(expectedParameterType),
+ "Wrong parameter type for " + p + ": expected " + expectedParameterType +
+ ", but got " + p.getType());
+
+ ParameterizedInfo[] expectedParameterizedTypes = epi.parameterizedTypes();
+ if (expectedParameterizedTypes.length > 0) {
+ Type parameterizedType = p.getParameterizedType();
+ Class extends Type> expectedParameterziedTypeType = expectedParameterizedTypes[i].value();
+ errorIfTrue(!expectedParameterziedTypeType.isAssignableFrom(parameterizedType.getClass()),
+ "Wrong class of parameteried type of " + p + ": expected " + expectedParameterziedTypeType +
+ ", but got " + parameterizedType.getClass());
+
+ if (expectedParameterziedTypeType.equals(Class.class)) {
+ errorIfTrue(!parameterizedType.equals(expectedParameterType),
+ "Wrong parameteried type for " + p + ": expected " + expectedParameterType +
+ ", but got " + parameterizedType);
+ } else {
+ if (expectedParameterziedTypeType.equals(ParameterizedType.class)) {
+ ParameterizedType ptype = (ParameterizedType)parameterizedType;
+ errorIfTrue(!ptype.getRawType().equals(expectedParameterType),
+ "Wrong raw type for " + p + ": expected " + expectedParameterType +
+ ", but got " + ptype.getRawType());
+ }
+
+ // Check string representation
+ String expectedStringOfType = epi.parameterizedTypes()[i].string();
+ errorIfTrue(!expectedStringOfType.equals(parameterizedType.toString()),
+ "Bad type string" + p + ": expected " + expectedStringOfType +
+ ", but got " + parameterizedType.toString());
}
}
- if(!parameters[0].getParameterizedType().equals(int.class)) {
- System.err.println("getParameterizedType for quux is wrong");
- error++;
- }
- if(!parameters[1].getParameterizedType().equals(Foo.class)) {
- System.err.println("getParameterizedType for quux is wrong");
- error++;
- }
- if(!(parameters[2].getParameterizedType() instanceof
- ParameterizedType)) {
- System.err.println("getParameterizedType for l is wrong");
- error++;
- } else {
- ParameterizedType pt =
- (ParameterizedType) parameters[2].getParameterizedType();
- if(!pt.getRawType().equals(List.class)) {
- System.err.println("Raw type for l is wrong");
- error++;
- }
- if(1 != pt.getActualTypeArguments().length) {
- System.err.println("Number of type parameters for l is wrong");
- error++;
- }
- if(!(pt.getActualTypeArguments()[0] instanceof WildcardType)) {
- System.err.println("Type parameter for l is wrong");
- error++;
- }
- }
- if(!(parameters[3].getParameterizedType() instanceof
- ParameterizedType)) {
- System.err.println("getParameterizedType for l2 is wrong");
- error++;
- } else {
- ParameterizedType pt =
- (ParameterizedType) parameters[3].getParameterizedType();
- if(!pt.getRawType().equals(List.class)) {
- System.err.println("Raw type for l2 is wrong");
- error++;
- }
- if(1 != pt.getActualTypeArguments().length) {
- System.err.println("Number of type parameters for l2 is wrong");
- error++;
- }
- if(!(pt.getActualTypeArguments()[0].equals(Foo.class))) {
- System.err.println("Type parameter for l2 is wrong");
- error++;
- }
- }
- if(!(parameters[4].getParameterizedType() instanceof
- ParameterizedType)) {
- System.err.println("getParameterizedType for l3 is wrong");
- error++;
- } else {
- ParameterizedType pt =
- (ParameterizedType) parameters[4].getParameterizedType();
- if(!pt.getRawType().equals(List.class)) {
- System.err.println("Raw type for l3 is wrong");
- error++;
- }
- if(1 != pt.getActualTypeArguments().length) {
- System.err.println("Number of type parameters for l3 is wrong");
- error++;
- }
- if(!(pt.getActualTypeArguments()[0] instanceof WildcardType)) {
- System.err.println("Type parameter for l3 is wrong");
- error++;
- } else {
- WildcardType wt = (WildcardType)
- pt.getActualTypeArguments()[0];
- if(!wt.getUpperBounds()[0].equals(Foo.class)) {
- System.err.println("Upper bounds on type parameter fol l3 is wrong");
- error++;
- }
- }
- }
- if(!parameters[5].isVarArgs()) {
- System.err.println("isVarArg for rest is wrong");
- error++;
- }
- if(!(parameters[5].getParameterizedType().equals(String[].class))) {
- System.err.println("getParameterizedType for rest is wrong");
- error++;
- }
-
}
}
- if(0 != error)
- throw new Exception("Failed " + error + " tests");
+ }
+
+ private void checkForErrors() {
+ if (errors > 0)
+ throw new RuntimeException("Failed " + errors + " tests");
+ }
+
+ private void errorIfTrue(boolean predicate, String errMessage) {
+ if (predicate) {
+ errors++;
+ System.err.println(errMessage);
+ }
+ }
+
+ private void abortIfTrue(boolean predicate, String errMessage) {
+ if (predicate) {
+ throw new RuntimeException(errMessage);
+ }
+ }
+
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({METHOD, CONSTRUCTOR})
+ @interface ExpectedParameterInfo {
+ int parameterCount() default 0;
+ Class>[] parameterTypes() default {};
+ ParameterizedInfo[] parameterizedTypes() default {};
+ boolean isVarArgs() default false;
+ }
+
+ @Target({})
+ @interface ParameterizedInfo {
+ Class extends Type> value() default Class.class;
+ String string() default "";
}
public class Foo {
int thing;
+ @ExpectedParameterInfo(parameterCount = 6,
+ parameterTypes =
+ {int.class, Foo.class,
+ List.class, List.class,
+ List.class, String[].class},
+ parameterizedTypes =
+ {@ParameterizedInfo(Class.class),
+ @ParameterizedInfo(Class.class),
+ @ParameterizedInfo(value=ParameterizedType.class, string="java.util.List>"),
+ @ParameterizedInfo(value=ParameterizedType.class, string="java.util.List