提交 a0a23261 编写于 作者: D darcy

8008279: Remove InvalidContainerAnnotationError.java

Reviewed-by: jfranck
上级 5c39a151
/*
* 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.annotation;
import java.util.Objects;
/**
* 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
* @jls 9.6 Annotation Types
* @jls 9.7 Annotations
*/
public class InvalidContainerAnnotationError extends AnnotationFormatError {
private static final long serialVersionUID = 5023L;
/**
* The instance of the erroneous container.
*/
private transient Annotation container;
/**
* The type of the annotation that should be contained in the
* container.
*/
private transient Class<? extends Annotation> annotationType;
/**
* Constructs a new InvalidContainerAnnotationError with the
* specified detail message.
*
* @param message the detail message.
*/
public InvalidContainerAnnotationError(String message) {
super(message);
}
/**
* Constructs a new InvalidContainerAnnotationError with the specified
* detail message and cause. Note that the detail message associated
* with {@code cause} is <i>not</i> automatically incorporated in
* this error's detail message.
*
* @param message the detail message
* @param cause the cause, may be {@code null}
*/
public InvalidContainerAnnotationError(String message, Throwable cause) {
super(message, cause);
}
/**
* Constructs a new InvalidContainerAnnotationError with the
* specified cause and a detail message of {@code (cause == null ?
* null : cause.toString())} (which typically contains the class
* and detail message of {@code cause}).
*
* @param cause the cause, may be {@code null}
*/
public InvalidContainerAnnotationError(Throwable cause) {
super(cause);
}
/**
* Constructs InvalidContainerAnnotationError for the specified
* container instance and contained annotation type.
*
* @param message the detail message
* @param cause the cause, may be {@code null}
* @param container the erroneous container instance, may be
* {@code null}
* @param annotationType the annotation type intended to be
* contained, may be {@code null}
*/
public InvalidContainerAnnotationError(String message,
Throwable cause,
Annotation container,
Class<? extends Annotation> annotationType) {
super(message, cause);
this.container = container;
this.annotationType = annotationType;
}
/**
* Returns the erroneous container.
*
* @return the erroneous container, may return {@code null}
*/
public Annotation getContainer() {
return container;
}
/**
* Returns the annotation type intended to be contained. Returns
* {@code null} if the annotation type intended to be contained
* could not be determined.
*
* @return the annotation type intended to be contained, or {@code
* null} if unknown
*/
public Class<? extends Annotation> getAnnotationType() {
return annotationType;
}
}
......@@ -26,6 +26,7 @@
package java.lang.reflect;
import java.lang.annotation.Annotation;
import java.lang.annotation.AnnotationFormatError;
/**
* Represents an annotated element of the program currently running in this
......@@ -86,8 +87,8 @@ import java.lang.annotation.Annotation;
*
* <p>Attempting to read annotations of a repeatable annotation type T
* that are contained in an annotation whose type is not, in fact, the
* containing annotation type of T will result in an
* InvalidContainerAnnotationError.
* containing annotation type of T, will result in an {@link
* AnnotationFormatError}.
*
* <p>Finally, attempting to read a member whose definition has evolved
* incompatibly will result in a {@link
......@@ -96,10 +97,9 @@ import java.lang.annotation.Annotation;
*
* @see java.lang.EnumConstantNotPresentException
* @see java.lang.TypeNotPresentException
* @see java.lang.annotation.AnnotationFormatError
* @see AnnotationFormatError
* @see java.lang.annotation.AnnotationTypeMismatchException
* @see java.lang.annotation.IncompleteAnnotationException
* @see java.lang.annotation.InvalidContainerAnnotationError
* @since 1.5
* @author Josh Bloch
*/
......
......@@ -86,11 +86,11 @@ public final class AnnotationSupport {
Class<? extends Annotation> containerClass = containerInstance.annotationType();
AnnotationType annoType = AnnotationType.getInstance(containerClass);
if (annoType == null)
throw new InvalidContainerAnnotationError(containerInstance + " is an invalid container for repeating annotations");
throw new AnnotationFormatError(containerInstance + " is an invalid container for repeating annotations");
Method m = annoType.members().get("value");
if (m == null)
throw new InvalidContainerAnnotationError(containerInstance +
throw new AnnotationFormatError(containerInstance +
" is an invalid container for repeating annotations");
m.setAccessible(true);
......@@ -103,11 +103,9 @@ public final class AnnotationSupport {
IllegalArgumentException | // parameters doesn't match
InvocationTargetException | // the value method threw an exception
ClassCastException e) { // well, a cast failed ...
throw new InvalidContainerAnnotationError(
throw new AnnotationFormatError(
containerInstance + " is an invalid container for repeating annotations",
e,
containerInstance,
null);
e);
}
}
......@@ -129,12 +127,10 @@ public final class AnnotationSupport {
return l;
} catch (ClassCastException |
NullPointerException e) {
throw new InvalidContainerAnnotationError(
throw new AnnotationFormatError(
String.format("%s is an invalid container for repeating annotations of type: %s",
containerInstance, annotationClass),
e,
containerInstance,
annotationClass);
e);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册