1 /*
2 * Copyright 2003-2004 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 package java.lang.annotation;
27 import java.lang.reflect.Method;
28
29 /**
30 * Thrown to indicate that a program has attempted to access an element of
31 * an annotation whose type has changed after the annotation was compiled
32 * (or serialized).
33 *
34 * @author Josh Bloch
35 * @since 1.5
36 */
37 public class AnnotationTypeMismatchException extends RuntimeException {
38 /**
39 * The <tt>Method</tt> object for the annotation element.
40 */
41 private final Method element;
42
43 /**
44 * The (erroneous) type of data found in the annotation. This string
45 * may, but is not required to, contain the value as well. The exact
46 * format of the string is unspecified.
47 */
48 private final String foundType;
49
50 /**
51 * Constructs an AnnotationTypeMismatchException for the specified
52 * annotation type element and found data type.
53 *
54 * @param element the <tt>Method</tt> object for the annotation element
55 * @param foundType the (erroneous) type of data found in the annotation.
56 * This string may, but is not required to, contain the value
57 * as well. The exact format of the string is unspecified.
58 */
59 public AnnotationTypeMismatchException(Method element, String foundType) {
60 super("Incorrectly typed data found for annotation element " + element
61 + " (Found data of type " + foundType + ")");
62 this.element = element;
63 this.foundType = foundType;
64 }
65
66 /**
67 * Returns the <tt>Method</tt> object for the incorrectly typed element.
68 *
69 * @return the <tt>Method</tt> object for the incorrectly typed element
70 */
71 public Method element() {
72 return this.element;
73 }
74
75 /**
76 * Returns the type of data found in the incorrectly typed element.
77 * The returned string may, but is not required to, contain the value
78 * as well. The exact format of the string is unspecified.
79 *
80 * @return the type of data found in the incorrectly typed element
81 */
82 public String foundType() {
83 return this.foundType;
84 }
85 }