1 /*
   2  * Copyright (c) 2012, 2013, 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 expected to act as a
  31  * container for another annotation type by virture of an @Repeatable
  32  * annotation, does not act as a container.
  33  *
  34  * @see   java.lang.reflect.AnnotatedElement
  35  * @since 1.8
  36  * @jls   9.6 Annotation Types
  37  * @jls   9.7 Annotations
  38  */
  39 public class InvalidContainerAnnotationError extends AnnotationFormatError {
  40     private static final long serialVersionUID = 5023L;
  41 
  42     /**
  43      * The instance of the erroneous container.
  44      */
  45     private transient Annotation container;
  46 
  47     /**
  48      * The type of the annotation that should be contained in the
  49      * container.
  50      */
  51     private transient Class<? extends Annotation> annotationType;
  52 
  53     /**
  54      * Constructs a new InvalidContainerAnnotationError with the
  55      * specified detail message.
  56      *
  57      * @param  message the detail message.
  58      */
  59     public InvalidContainerAnnotationError(String message) {
  60         super(message);
  61     }
  62 
  63     /**
  64      * Constructs a new InvalidContainerAnnotationError with the specified
  65      * detail message and cause.  Note that the detail message associated
  66      * with {@code cause} is <i>not</i> automatically incorporated in
  67      * this error's detail message.
  68      *
  69      * @param message the detail message
  70      * @param cause the cause, may be {@code null}
  71      */
  72     public InvalidContainerAnnotationError(String message, Throwable cause) {
  73         super(message, cause);
  74     }
  75 
  76     /**
  77      * Constructs a new InvalidContainerAnnotationError with the
  78      * specified cause and a detail message of {@code (cause == null ?
  79      * null : cause.toString())} (which typically contains the class
  80      * and detail message of {@code cause}).
  81      *
  82      * @param cause the cause, may be {@code null}
  83      */
  84     public InvalidContainerAnnotationError(Throwable cause) {
  85         super(cause);
  86     }
  87 
  88     /**
  89      * Constructs InvalidContainerAnnotationError for the specified
  90      * container instance and contained annotation type.
  91      *
  92      * @param  message the detail message
  93      * @param  cause the cause, may be {@code null}
  94      * @param container the erroneous container instance, may be
  95      *        {@code null}
  96      * @param annotationType the annotation type intended to be
  97      *        contained, may be {@code null}
  98      */
  99     public InvalidContainerAnnotationError(String message,
 100                                            Throwable cause,
 101                                            Annotation container,
 102                                            Class<? extends Annotation> annotationType) {
 103         super(message, cause);
 104         this.container = container;
 105         this.annotationType = annotationType;
 106     }
 107 
 108     /**
 109      * Returns the erroneous container.
 110      *
 111      * @return the erroneous container, may return {@code null}
 112      */
 113     public Annotation getContainer() {
 114         return container;
 115     }
 116 
 117     /**
 118      * Returns the annotation type intended to be contained. Returns
 119      * {@code null} if the annotation type intended to be contained
 120      * could not be determined.
 121      *
 122      * @return the annotation type intended to be contained, or {@code
 123      * null} if unknown
 124      */
 125     public Class<? extends Annotation> getAnnotationType() {
 126         return annotationType;
 127     }
 128 }