Home | History | Annotate | Download | only in annotation
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements. See the NOTICE file distributed with this
      4  * work for additional information regarding copyright ownership. The ASF
      5  * licenses this file to you under the Apache License, Version 2.0 (the
      6  * "License"); you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  * http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     14  * License for the specific language governing permissions and limitations under
     15  * the License.
     16  */
     17 
     18 package java.lang.annotation;
     19 
     20 import java.lang.reflect.Method;
     21 
     22 /**
     23  * Indicates that an annotation type has changed since it was compiled or
     24  * serialized.
     25  *
     26  * @since 1.5
     27  */
     28 public class AnnotationTypeMismatchException extends RuntimeException {
     29 
     30     private static final long serialVersionUID = 8125925355765570191L;
     31 
     32     private Method element;
     33 
     34     private String foundType;
     35 
     36     /**
     37      * Constructs an instance for the given type element and the type found.
     38      *
     39      * @param element
     40      *            the annotation type element.
     41      * @param foundType
     42      *            the invalid type that was found. This is actually the textual
     43      *            type description found in the binary class representation,
     44      *            so it may not be human-readable.
     45      */
     46     public AnnotationTypeMismatchException(Method element, String foundType) {
     47         super("The annotation element " + element + " doesn't match the type " + foundType);
     48         this.element = element;
     49         this.foundType = foundType;
     50     }
     51 
     52     /**
     53      * Returns the method object for the invalid type.
     54      *
     55      * @return a {@link Method} instance.
     56      */
     57     public Method element() {
     58         return element;
     59     }
     60 
     61     /**
     62      * Returns the invalid type.
     63      *
     64      * @return a string describing the invalid data.
     65      */
     66     public String foundType() {
     67         return foundType;
     68     }
     69 }
     70