1. /*
  2. * @(#)AnnotationTypeMismatchException.java 1.3 04/04/12
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.lang.annotation;
  8. import java.lang.reflect.Method;
  9. /**
  10. * Thrown to indicate that a program has attempted to access an element of
  11. * an annotation whose type has changed after the annotation was compiled
  12. * (or serialized).
  13. *
  14. * @author Josh Bloch
  15. * @since 1.5
  16. */
  17. public class AnnotationTypeMismatchException extends RuntimeException {
  18. /**
  19. * The <tt>Method</tt> object for the annotation element.
  20. */
  21. private final Method element;
  22. /**
  23. * The (erroneous) type of data found in the annotation. This string
  24. * may, but is not required to, contain the value as well. The exact
  25. * format of the string is unspecified.
  26. */
  27. private final String foundType;
  28. /**
  29. * Constructs an AnnotationTypeMismatchException for the specified
  30. * annotation type element and found data type.
  31. *
  32. * @param element the <tt>Method</tt> object for the annotation element
  33. * @param foundType the (erroneous) type of data found in the annotation.
  34. * This string may, but is not required to, contain the value
  35. * as well. The exact format of the string is unspecified.
  36. */
  37. public AnnotationTypeMismatchException(Method element, String foundType) {
  38. super("Incorrectly typed data found for annotation element " + element
  39. + " (Found data of type " + foundType + ")");
  40. this.element = element;
  41. this.foundType = foundType;
  42. }
  43. /**
  44. * Returns the <tt>Method</tt> object for the incorrectly typed element.
  45. *
  46. * @return the <tt>Method</tt> object for the incorrectly typed element
  47. */
  48. public Method element() {
  49. return this.element;
  50. }
  51. /**
  52. * Returns the type of data found in the incorrectly typed element.
  53. * The returned string may, but is not required to, contain the value
  54. * as well. The exact format of the string is unspecified.
  55. *
  56. * @return the type of data found in the incorrectly typed element
  57. */
  58. public String foundType() {
  59. return this.foundType();
  60. }
  61. }