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 a8bbd962f34a -r 41654275896d src/share/classes/java/lang/annotation/ContainerFor.java
--- a/src/share/classes/java/lang/annotation/ContainerFor.java Mon Jan 28 16:29:10 2013 -0400
+++ /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 a8bbd962f34a -r 41654275896d src/share/classes/java/lang/annotation/InvalidContainerAnnotationError.java
--- a/src/share/classes/java/lang/annotation/InvalidContainerAnnotationError.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/lang/annotation/InvalidContainerAnnotationError.java Mon Feb 04 17:29:58 2013 -0400
@@ -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 a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/AnnotatedArrayType.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/java/lang/reflect/AnnotatedArrayType.java Mon Feb 04 17:29:58 2013 -0400
@@ -0,0 +1,43 @@
+/*
+ * 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
+ * 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.reflect;
+
+
+/**
+ * AnnotatedArrayType represents the use of an array type, whose component
+ * type may itself represent the annotated use of a type.
+ *
+ * @since 1.8
+ */
+public interface AnnotatedArrayType extends AnnotatedType {
+
+ /**
+ * Returns the annotated generic component type of this array type.
+ *
+ * @return the annotated generic component type of this array type
+ */
+ AnnotatedType getAnnotatedGenericComponentType();
+}
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/AnnotatedElement.java
--- a/src/share/classes/java/lang/reflect/AnnotatedElement.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/lang/reflect/AnnotatedElement.java Mon Feb 04 17:29:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -35,6 +35,24 @@
* arrays returned by accessors for array-valued enum members; it will
* have no affect on the arrays returned to other callers.
*
+ *
If an annotation returned by a method in this interface contains
* (directly or indirectly) a {@link Class}-valued member referring to
* a class that is not accessible in this VM, attempting to read the class
@@ -50,7 +68,7 @@
* containing annotation type of T will result in an
* InvalidContainerAnnotationError.
*
- *
Finally, attempting to read a member whose definition has evolved
* incompatibly will result in a {@link
* java.lang.annotation.AnnotationTypeMismatchException} or an
* {@link java.lang.annotation.IncompleteAnnotationException}.
@@ -70,6 +88,9 @@
* is present on this element, else false. This method
* is designed primarily for convenient access to marker annotations.
*
+ *
The truth value returned by this method is equivalent to:
+ * {@code getAnnotation(annotationClass) != null}
+ *
* @param annotationClass the Class object corresponding to the
* annotation type
* @return true if an annotation for the specified annotation
@@ -110,12 +131,15 @@
T[] getAnnotations(Class annotationClass);
/**
- * Returns all annotations present on this element. (Returns an array
- * of length zero if this element has no annotations.) The caller of
- * this method is free to modify the returned array; it will have no
- * effect on the arrays returned to other callers.
+ * Returns annotations that are present on this element.
+ *
+ * If there are no annotations present on this element, the return
+ * value is an array of length 0.
*
- * @return all annotations present on this element
+ * The caller of this method is free to modify the returned array; it will
+ * have no effect on the arrays returned to other callers.
+ *
+ * @return annotations present on this element
* @since 1.5
*/
Annotation[] getAnnotations();
@@ -157,14 +181,16 @@
T[] getDeclaredAnnotations(Class annotationClass);
/**
- * Returns all annotations that are directly present on this
- * element. This method ignores inherited annotations. (Returns
- * an array of length zero if no annotations are directly present
- * on this element.) The caller of this method is free to modify
- * the returned array; it will have no effect on the arrays
- * returned to other callers.
+ * Returns annotations that are directly present on this element.
+ * This method ignores inherited annotations.
*
- * @return All annotations directly present on this element
+ * If there are no annotations directly present on this element,
+ * the return value is an array of length 0.
+ *
+ * The caller of this method is free to modify the returned array; it will
+ * have no effect on the arrays returned to other callers.
+ *
+ * @return annotations directly present on this element
* @since 1.5
*/
Annotation[] getDeclaredAnnotations();
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/AnnotatedParameterizedType.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/java/lang/reflect/AnnotatedParameterizedType.java Mon Feb 04 17:29:58 2013 -0400
@@ -0,0 +1,42 @@
+/*
+ * 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
+ * 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.reflect;
+
+/**
+ * AnnotatedParameterizedType represents the use of a parameterized type,
+ * whose type arguments may themselves represent annotated uses of types.
+ *
+ * @since 1.8
+ */
+public interface AnnotatedParameterizedType extends AnnotatedType {
+
+ /**
+ * Returns the annotated actual type arguments of this parameterized type.
+ *
+ * @return the annotated actual type arguments of this parameterized type
+ */
+ AnnotatedType[] getAnnotatedActualTypeArguments();
+}
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/AnnotatedType.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/java/lang/reflect/AnnotatedType.java Mon Feb 04 17:29:58 2013 -0400
@@ -0,0 +1,44 @@
+/*
+ * 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
+ * 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.reflect;
+
+/**
+ * AnnotatedType represents the annotated use of a type in the program
+ * currently running in this VM. The use may be of any type in the Java
+ * programming language, including an array type, a parameterized type, a type
+ * variable, or a wildcard type.
+ *
+ * @since 1.8
+ */
+public interface AnnotatedType extends AnnotatedElement {
+
+ /**
+ * Returns the underlying type that this annotated type represents.
+ *
+ * @return the type this annotated type represents
+ */
+ public Type getType();
+}
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/AnnotatedTypeVariable.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/java/lang/reflect/AnnotatedTypeVariable.java Mon Feb 04 17:29:58 2013 -0400
@@ -0,0 +1,43 @@
+/*
+ * 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
+ * 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.reflect;
+
+/**
+ * AnnotatedTypeVariable represents the use of a type variable, whose
+ * declaration may have bounds which themselves represent annotated uses of
+ * types.
+ *
+ * @since 1.8
+ */
+public interface AnnotatedTypeVariable extends AnnotatedType {
+
+ /**
+ * Returns the annotated bounds of this type variable.
+ *
+ * @return the annotated bounds of this type variable
+ */
+ AnnotatedType[] getAnnotatedBounds();
+}
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/AnnotatedWildcardType.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/java/lang/reflect/AnnotatedWildcardType.java Mon Feb 04 17:29:58 2013 -0400
@@ -0,0 +1,49 @@
+/*
+ * 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
+ * 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.reflect;
+
+/**
+ * AnnotatedWildcardType represents the use of a wildcard type argument, whose
+ * upper or lower bounds may themselves represent annotated uses of types.
+ *
+ * @since 1.8
+ */
+public interface AnnotatedWildcardType extends AnnotatedType {
+
+ /**
+ * Returns the annotated lower bounds of this wildcard type.
+ *
+ * @return the annotated lower bounds of this wildcard type
+ */
+ AnnotatedType[] getAnnotatedLowerBounds();
+
+ /**
+ * Returns the annotated upper bounds of this wildcard type.
+ *
+ * @return the annotated upper bounds of this wildcard type
+ */
+ AnnotatedType[] getAnnotatedUpperBounds();
+}
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/Constructor.java
--- a/src/share/classes/java/lang/reflect/Constructor.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/lang/reflect/Constructor.java Mon Feb 04 17:29:58 2013 -0400
@@ -154,6 +154,10 @@
byte[] getAnnotationBytes() {
return annotations;
}
+ @Override
+ byte[] getTypeAnnotationBytes() {
+ return typeAnnotations;
+ }
/**
* {@inheritDoc}
@@ -523,4 +527,12 @@
}
}
}
+
+ /**
+ * {@inheritDoc}
+ * @since 1.8
+ */
+ public AnnotatedType getAnnotatedReturnType() {
+ return getAnnotatedReturnType0(getDeclaringClass());
+ }
}
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/Executable.java
--- a/src/share/classes/java/lang/reflect/Executable.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/lang/reflect/Executable.java Mon Feb 04 17:29:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 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
@@ -26,11 +26,12 @@
package java.lang.reflect;
import java.lang.annotation.*;
-import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import sun.reflect.annotation.AnnotationParser;
import sun.reflect.annotation.AnnotationSupport;
+import sun.reflect.annotation.TypeAnnotationParser;
+import sun.reflect.annotation.TypeAnnotation;
import sun.reflect.generics.repository.ConstructorRepository;
/**
@@ -50,6 +51,7 @@
* Accessor method to allow code sharing
*/
abstract byte[] getAnnotationBytes();
+ abstract byte[] getTypeAnnotationBytes();
/**
* Does the Executable have generic information.
@@ -435,8 +437,7 @@
*/
public T getAnnotation(Class annotationClass) {
Objects.requireNonNull(annotationClass);
-
- return AnnotationSupport.getOneAnnotation(declaredAnnotations(), annotationClass);
+ return annotationClass.cast(declaredAnnotations().get(annotationClass));
}
/**
@@ -454,7 +455,7 @@
* {@inheritDoc}
*/
public Annotation[] getDeclaredAnnotations() {
- return AnnotationSupport.unpackToArray(declaredAnnotations());
+ return AnnotationParser.toArray(declaredAnnotations());
}
private transient Map, Annotation> declaredAnnotations;
@@ -470,4 +471,86 @@
return declaredAnnotations;
}
+
+ /* Helper for subclasses of Executable.
+ *
+ * Returns an AnnotatedType object that represents the use of a type to
+ * specify the return type of the method/constructor represented by this
+ * Executable.
+ *
+ * @since 1.8
+ */
+ AnnotatedType getAnnotatedReturnType0(Type returnType) {
+ return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes(),
+ sun.misc.SharedSecrets.getJavaLangAccess().
+ getConstantPool(getDeclaringClass()),
+ this,
+ getDeclaringClass(),
+ returnType,
+ TypeAnnotation.TypeAnnotationTarget.METHOD_RETURN_TYPE);
+ }
+
+ /**
+ * Returns an AnnotatedType object that represents the use of a type to
+ * specify the receiver type of the method/constructor represented by this
+ * Executable. The receiver type of a method/constructor is available only
+ * if the method/constructor declares a formal parameter called 'this'.
+ *
+ * Returns null if this Executable represents a constructor or instance
+ * method that either declares no formal parameter called 'this', or
+ * declares a formal parameter called 'this' with no annotations on its
+ * type.
+ *
+ * Returns null if this Executable represents a static method.
+ *
+ * @since 1.8
+ */
+ public AnnotatedType getAnnotatedReceiverType() {
+ return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes(),
+ sun.misc.SharedSecrets.getJavaLangAccess().
+ getConstantPool(getDeclaringClass()),
+ this,
+ getDeclaringClass(),
+ getDeclaringClass(),
+ TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER_TYPE);
+ }
+
+ /**
+ * Returns an array of AnnotatedType objects that represent the use of
+ * types to specify formal parameter types of the method/constructor
+ * represented by this Executable. The order of the objects in the array
+ * corresponds to the order of the formal parameter types in the
+ * declaration of the method/constructor.
+ *
+ * Returns an array of length 0 if the method/constructor declares no
+ * parameters.
+ *
+ * @since 1.8
+ */
+ public AnnotatedType[] getAnnotatedParameterTypes() {
+ throw new UnsupportedOperationException("Not yet");
+ }
+
+ /**
+ * Returns an array of AnnotatedType objects that represent the use of
+ * types to specify the declared exceptions of the method/constructor
+ * represented by this Executable. The order of the objects in the array
+ * corresponds to the order of the exception types in the declaration of
+ * the method/constructor.
+ *
+ * Returns an array of length 0 if the method/constructor declares no
+ * exceptions.
+ *
+ * @since 1.8
+ */
+ public AnnotatedType[] getAnnotatedExceptionTypes() {
+ return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes(),
+ sun.misc.SharedSecrets.getJavaLangAccess().
+ getConstantPool(getDeclaringClass()),
+ this,
+ getDeclaringClass(),
+ getGenericExceptionTypes(),
+ TypeAnnotation.TypeAnnotationTarget.THROWS);
+ }
+
}
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/Field.java
--- a/src/share/classes/java/lang/reflect/Field.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/lang/reflect/Field.java Mon Feb 04 17:29:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -36,7 +36,8 @@
import java.util.Objects;
import sun.reflect.annotation.AnnotationParser;
import sun.reflect.annotation.AnnotationSupport;
-
+import sun.reflect.annotation.TypeAnnotation;
+import sun.reflect.annotation.TypeAnnotationParser;
/**
* A {@code Field} provides information about, and dynamic access to, a
@@ -1020,8 +1021,7 @@
*/
public T getAnnotation(Class annotationClass) {
Objects.requireNonNull(annotationClass);
-
- return AnnotationSupport.getOneAnnotation(declaredAnnotations(), annotationClass);
+ return annotationClass.cast(declaredAnnotations().get(annotationClass));
}
/**
@@ -1039,7 +1039,7 @@
* {@inheritDoc}
*/
public Annotation[] getDeclaredAnnotations() {
- return AnnotationSupport.unpackToArray(declaredAnnotations());
+ return AnnotationParser.toArray(declaredAnnotations());
}
private transient Map, Annotation> declaredAnnotations;
@@ -1053,4 +1053,20 @@
}
return declaredAnnotations;
}
+
+ /**
+ * Returns an AnnotatedType object that represents the use of a type to specify
+ * the declared type of the field represented by this Field.
+ *
+ * @since 1.8
+ */
+ public AnnotatedType getAnnotatedType() {
+ return TypeAnnotationParser.buildAnnotatedType(typeAnnotations,
+ sun.misc.SharedSecrets.getJavaLangAccess().
+ getConstantPool(getDeclaringClass()),
+ this,
+ getDeclaringClass(),
+ getGenericType(),
+ TypeAnnotation.TypeAnnotationTarget.FIELD_TYPE);
}
+}
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/Method.java
--- a/src/share/classes/java/lang/reflect/Method.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/lang/reflect/Method.java Mon Feb 04 17:29:58 2013 -0400
@@ -165,6 +165,10 @@
byte[] getAnnotationBytes() {
return annotations;
}
+ @Override
+ byte[] getTypeAnnotationBytes() {
+ return typeAnnotations;
+ }
/**
* {@inheritDoc}
@@ -621,6 +625,14 @@
return sharedGetParameterAnnotations(parameterTypes, parameterAnnotations);
}
+ /**
+ * {@inheritDoc}
+ * @since 1.8
+ */
+ public AnnotatedType getAnnotatedReturnType() {
+ return getAnnotatedReturnType0(getGenericReturnType());
+ }
+
@Override
void handleParameterNumberMismatch(int resultLength, int numParameters) {
throw new AnnotationFormatError("Parameter annotations don't match number of parameters");
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/Parameter.java
--- a/src/share/classes/java/lang/reflect/Parameter.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/lang/reflect/Parameter.java Mon Feb 04 17:29:58 2013 -0400
@@ -233,8 +233,7 @@
*/
public T getAnnotation(Class annotationClass) {
Objects.requireNonNull(annotationClass);
-
- return AnnotationSupport.getOneAnnotation(declaredAnnotations(), annotationClass);
+ return annotationClass.cast(declaredAnnotations().get(annotationClass));
}
/**
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/ReflectAccess.java
--- a/src/share/classes/java/lang/reflect/ReflectAccess.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/lang/reflect/ReflectAccess.java Mon Feb 04 17:29:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -128,6 +128,10 @@
return c.getRawParameterAnnotations();
}
+ public byte[] getExecutableTypeAnnotationBytes(Executable ex) {
+ return ex.getTypeAnnotationBytes();
+ }
+
//
// Copying routines, needed to quickly fabricate new Field,
// Method, and Constructor objects from templates
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/lang/reflect/TypeVariable.java
--- a/src/share/classes/java/lang/reflect/TypeVariable.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/lang/reflect/TypeVariable.java Mon Feb 04 17:29:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -86,4 +86,16 @@
* @return the name of this type variable, as it appears in the source code
*/
String getName();
+
+ /**
+ * Returns an array of AnnotatedType objects that represent the use of
+ * types to denote the upper bounds of the type parameter represented by
+ * this TypeVariable. The order of the objects in the array corresponds to
+ * the order of the bounds in the declaration of the type parameter.
+ *
+ * Returns an array of length 0 if the type parameter declares no bounds.
+ *
+ * @since 1.8
+ */
+ AnnotatedType[] getAnnotatedBounds();
}
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/math/BigDecimal.java
--- a/src/share/classes/java/math/BigDecimal.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/math/BigDecimal.java Mon Feb 04 17:29:58 2013 -0400
@@ -3537,13 +3537,25 @@
else
return expandBigIntegerTenPowers(n);
}
- // BigInteger.pow is slow, so make 10**n by constructing a
- // BigInteger from a character string (still not very fast)
- char tenpow[] = new char[n + 1];
- tenpow[0] = '1';
- for (int i = 1; i <= n; i++)
- tenpow[i] = '0';
- return new BigInteger(tenpow,1, tenpow.length);
+
+ if (n < 1024*524288) {
+ // BigInteger.pow is slow, so make 10**n by constructing a
+ // BigInteger from a character string (still not very fast)
+ // which occupies no more than 1GB (!) of memory.
+ char tenpow[] = new char[n + 1];
+ tenpow[0] = '1';
+ for (int i = 1; i <= n; i++) {
+ tenpow[i] = '0';
+ }
+ return new BigInteger(tenpow, 1, tenpow.length);
+ }
+
+ if ((n & 0x1) == 0x1) {
+ return BigInteger.TEN.multiply(bigTenToThe(n - 1));
+ } else {
+ BigInteger tmp = bigTenToThe(n/2);
+ return tmp.multiply(tmp);
+ }
}
/**
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/util/Base64.java
--- a/src/share/classes/java/util/Base64.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/util/Base64.java Mon Feb 04 17:29:58 2013 -0400
@@ -64,7 +64,8 @@
* RFC 2045 for encoding and decoding operation. The encoded output
* must be represented in lines of no more than 76 characters each
* and uses a carriage return {@code '\r'} followed immediately by
- * a linefeed {@code '\n'} as the line separator. All line separators
+ * a linefeed {@code '\n'} as the line separator. No line separator
+ * is added to the end of the encoded output. All line separators
* or other characters not found in the base64 alphabet table are
* ignored in decoding operation.
*
@@ -413,6 +414,7 @@
* specified Base64 encoded format
*/
public OutputStream wrap(OutputStream os) {
+ Objects.requireNonNull(os);
return new EncOutputStream(os, isURL ? toBase64URL : toBase64,
newline, linemax);
}
@@ -613,6 +615,13 @@
* This class implements a decoder for decoding byte data using the
* Base64 encoding scheme as specified in RFC 4648 and RFC 2045.
*
+ * The Base64 padding character {@code '='} is accepted and
+ * interpreted as the end of the encoded byte data, but is not
+ * required. So if the final unit of the encoded byte data only has
+ * two or three Base64 characters (without the corresponding padding
+ * character(s) padded), they are decoded as if followed by padding
+ * character(s).
+ *
*
Instances of {@link Decoder} class are safe for use by
* multiple concurrent threads.
*
@@ -695,7 +704,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
@@ -856,6 +865,9 @@
/**
* Returns an input stream for decoding {@link Base64} encoded byte stream.
*
+ *
The {@code read} methods of the returned {@code InputStream} will
+ * throw {@code IOException} when reading bytes that cannot be decoded.
+ *
*
Closing the returned input stream will close the underlying
* input stream.
*
@@ -866,6 +878,7 @@
* byte stream
*/
public InputStream wrap(InputStream is) {
+ Objects.requireNonNull(is);
return new DecInputStream(is, isURL ? fromBase64URL : fromBase64, isMIME);
}
@@ -881,13 +894,16 @@
int dl = dst.arrayOffset() + dst.limit();
int dp0 = dp;
int mark = sp;
- boolean padding = false;
try {
while (sp < sl) {
int b = sa[sp++] & 0xff;
if ((b = base64[b]) < 0) {
if (b == -2) { // padding byte
- padding = true;
+ if (shiftto == 6 && (sp == sl || sa[sp++] != '=') ||
+ shiftto == 18) {
+ throw new IllegalArgumentException(
+ "Input byte array has wrong 4-byte ending unit");
+ }
break;
}
if (isMIME) // skip if for rfc2045
@@ -913,24 +929,23 @@
if (shiftto == 6) {
if (dl - dp < 1)
return dp - dp0;
- if (padding && (sp + 1 != sl || sa[sp++] != '='))
- throw new IllegalArgumentException(
- "Input buffer has wrong 4-byte ending unit");
da[dp++] = (byte)(bits >> 16);
- mark = sp;
} else if (shiftto == 0) {
if (dl - dp < 2)
return dp - dp0;
- if (padding && sp != sl)
- throw new IllegalArgumentException(
- "Input buffer has wrong 4-byte ending unit");
da[dp++] = (byte)(bits >> 16);
da[dp++] = (byte)(bits >> 8);
- mark = sp;
- } else if (padding || shiftto != 18) {
+ } else if (shiftto == 12) {
throw new IllegalArgumentException(
"Last unit does not have enough valid bits");
}
+ while (sp < sl) {
+ if (isMIME && base64[sa[sp++]] < 0)
+ continue;
+ throw new IllegalArgumentException(
+ "Input byte array has incorrect ending byte at " + sp);
+ }
+ mark = sp;
return dp - dp0;
} finally {
src.position(mark);
@@ -948,14 +963,16 @@
int dl = dst.limit();
int dp0 = dp;
int mark = sp;
- boolean padding = false;
-
try {
while (sp < sl) {
int b = src.get(sp++) & 0xff;
if ((b = base64[b]) < 0) {
if (b == -2) { // padding byte
- padding = true;
+ if (shiftto == 6 && (sp == sl || src.get(sp++) != '=') ||
+ shiftto == 18) {
+ throw new IllegalArgumentException(
+ "Input byte array has wrong 4-byte ending unit");
+ }
break;
}
if (isMIME) // skip if for rfc2045
@@ -981,24 +998,23 @@
if (shiftto == 6) {
if (dl - dp < 1)
return dp - dp0;
- if (padding && (sp + 1 != sl || src.get(sp++) != '='))
- throw new IllegalArgumentException(
- "Input buffer has wrong 4-byte ending unit");
dst.put(dp++, (byte)(bits >> 16));
- mark = sp;
} else if (shiftto == 0) {
if (dl - dp < 2)
return dp - dp0;
- if (padding && sp != sl)
- throw new IllegalArgumentException(
- "Input buffer has wrong 4-byte ending unit");
dst.put(dp++, (byte)(bits >> 16));
dst.put(dp++, (byte)(bits >> 8));
- mark = sp;
- } else if (padding || shiftto != 18) {
+ } else if (shiftto == 12) {
throw new IllegalArgumentException(
"Last unit does not have enough valid bits");
}
+ while (sp < sl) {
+ if (isMIME && base64[src.get(sp++)] < 0)
+ continue;
+ throw new IllegalArgumentException(
+ "Input byte array has incorrect ending byte at " + sp);
+ }
+ mark = sp;
return dp - dp0;
} finally {
src.position(mark);
@@ -1012,9 +1028,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] == '=')
@@ -1043,12 +1062,20 @@
int dp = 0;
int bits = 0;
int shiftto = 18; // pos of first byte of 4-byte atom
- boolean padding = false;
while (sp < sl) {
int b = src[sp++] & 0xff;
if ((b = base64[b]) < 0) {
- if (b == -2) { // padding byte
- padding = true;
+ if (b == -2) { // padding byte '='
+ // xx= shiftto==6&&sp==sl missing last =
+ // xx=y shiftto==6 last is not =
+ // = shiftto==18 unnecessary padding
+ // x= shiftto==12 be taken care later
+ // together with single x, invalid anyway
+ if (shiftto == 6 && (sp == sl || src[sp++] != '=') ||
+ shiftto == 18) {
+ throw new IllegalArgumentException(
+ "Input byte array has wrong 4-byte ending unit");
+ }
break;
}
if (isMIME) // skip if for rfc2045
@@ -1068,22 +1095,23 @@
bits = 0;
}
}
- // reach end of byte arry or hit padding '=' characters.
- // if '=' presents, they must be the last one or two.
- if (shiftto == 6) { // xx==
- if (padding && (sp + 1 != sl || src[sp] != '='))
- throw new IllegalArgumentException(
- "Input byte array has wrong 4-byte ending unit");
+ // reached end of byte array or hit padding '=' characters.
+ if (shiftto == 6) {
dst[dp++] = (byte)(bits >> 16);
- } else if (shiftto == 0) { // xxx=
- if (padding && sp != sl)
- throw new IllegalArgumentException(
- "Input byte array has wrong 4-byte ending unit");
+ } else if (shiftto == 0) {
dst[dp++] = (byte)(bits >> 16);
dst[dp++] = (byte)(bits >> 8);
- } else if (padding || shiftto != 18) {
- throw new IllegalArgumentException(
- "last unit does not have enough bytes");
+ } else if (shiftto == 12) {
+ throw new IllegalArgumentException(
+ "Last unit does not have enough valid bits");
+ }
+ // anything left is invalid, if is not MIME.
+ // if MIME, ignore all non-base64 character
+ while (sp < sl) {
+ if (isMIME && base64[src[sp++]] < 0)
+ continue;
+ throw new IllegalArgumentException(
+ "Input byte array has incorrect ending byte at " + sp);
}
return dp;
}
@@ -1247,8 +1275,22 @@
int v = is.read();
if (v == -1) {
eof = true;
- if (nextin != 18)
- throw new IOException("Base64 stream has un-decoded dangling byte(s).");
+ if (nextin != 18) {
+ if (nextin == 12)
+ throw new IOException("Base64 stream has one un-decoded dangling byte.");
+ // treat ending xx/xxx without padding character legal.
+ // same logic as v == 'v' below
+ b[off++] = (byte)(bits >> (16));
+ len--;
+ if (nextin == 0) { // only one padding byte
+ if (len == 0) { // no enough output space
+ bits >>= 8; // shift to lowest byte
+ nextout = 0;
+ } else {
+ b[off++] = (byte) (bits >> 8);
+ }
+ }
+ }
if (off == oldOff)
return -1;
else
diff -r a8bbd962f34a -r 41654275896d src/share/classes/java/util/Formatter.java
--- a/src/share/classes/java/util/Formatter.java Mon Jan 28 16:29:10 2013 -0400
+++ b/src/share/classes/java/util/Formatter.java Mon Feb 04 17:29:58 2013 -0400
@@ -351,7 +351,9 @@
*
{@code 'a'}, {@code 'A'}
* | floating point
* | The result is formatted as a hexadecimal floating-point number with
- * a significand and an exponent
+ * a significand and an exponent. This conversion is not supported
+ * for the {@code BigDecimal} type despite the latter's being in the
+ * floating point argument category.
*
* |