1 /* 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package java.lang.annotation; 26 27 import java.util.Objects; 28 29 /** 30 * Thrown to indicate that an annotation type whose declaration is 31 * (meta-)annotated with a {@link ContainerFor} annotation is not, in 32 * fact, the <em>containing annotation type of the type named by {@link 33 * ContainerFor}</em>. 34 * 35 * @see java.lang.reflect.AnnotatedElement 36 * @since 1.8 37 * @jls 9.6 Annotation Types 38 * @jls 9.7 Annotations 39 */ 40 public class InvalidContainerAnnotationError extends AnnotationFormatError { 41 private static final long serialVersionUID = 5023L; 42 43 /** 44 * The instance of the erroneous container. 45 */ 46 private transient Annotation container; 47 48 /** 49 * The type of the annotation that should be contained in the 50 * container. 51 */ 52 private transient Class<? extends Annotation> annotationType; 53 54 /** 55 * Constructs a new InvalidContainerAnnotationError with the 56 * specified detail message. 57 * 58 * @param message the detail message. 59 */ 60 public InvalidContainerAnnotationError(String message) { 61 super(message); 62 } 63 64 /** 65 * Constructs a new InvalidContainerAnnotationError with the specified 66 * detail message and cause. Note that the detail message associated 67 * with {@code cause} is <i>not</i> automatically incorporated in 68 * this error's detail message. 69 * 70 * @param message the detail message 71 * @param cause the cause, may be {@code null} 72 */ 73 public InvalidContainerAnnotationError(String message, Throwable cause) { 74 super(message, cause); 75 } 76 77 /** 78 * Constructs a new InvalidContainerAnnotationError with the 79 * specified cause and a detail message of {@code (cause == null ? 80 * null : cause.toString())} (which typically contains the class 81 * and detail message of {@code cause}). 82 * 83 * @param cause the cause, may be {@code null} 84 */ 85 public InvalidContainerAnnotationError(Throwable cause) { 86 super(cause); 87 } 88 89 /** 90 * Constructs InvalidContainerAnnotationError for the specified 91 * container instance and contained annotation type. 92 * 93 * @param message the detail message 94 * @param cause the cause, may be {@code null} 95 * @param container the erroneous container instance, may be 96 * {@code null} 97 * @param annotationType the annotation type intended to be 98 * contained, may be {@code null} 99 */ 100 public InvalidContainerAnnotationError(String message, 101 Throwable cause, 102 Annotation container, 103 Class<? extends Annotation> annotationType) { 104 super(message, cause); 105 this.container = container; 106 this.annotationType = annotationType; 107 } 108 109 /** 110 * Returns the erroneous container. 111 * 112 * @return the erroneous container, may return {@code null} 113 */ 114 public Annotation getContainer() { 115 return container; 116 } 117 118 /** 119 * Returns the annotation type intended to be contained. Returns 120 * {@code null} if the annotation type intended to be contained 121 * could not be determined. 122 * 123 * @return the annotation type intended to be contained, or {@code 124 * null} if unknown 125 */ 126 public Class<? extends Annotation> getAnnotationType() { 127 return annotationType; 128 } 129 }