1 /*
   2  * Copyright (c) 1996, 2018, 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 
  26 package java.lang.reflect;
  27 
  28 import jdk.internal.HotSpotIntrinsicCandidate;
  29 import jdk.internal.access.SharedSecrets;
  30 import jdk.internal.reflect.CallerSensitive;
  31 import jdk.internal.reflect.MethodAccessor;
  32 import jdk.internal.reflect.Reflection;
  33 import jdk.internal.vm.annotation.ForceInline;
  34 import sun.reflect.annotation.ExceptionProxy;
  35 import sun.reflect.annotation.TypeNotPresentExceptionProxy;
  36 import sun.reflect.generics.repository.MethodRepository;
  37 import sun.reflect.generics.factory.CoreReflectionFactory;
  38 import sun.reflect.generics.factory.GenericsFactory;
  39 import sun.reflect.generics.scope.MethodScope;
  40 import sun.reflect.annotation.AnnotationType;
  41 import sun.reflect.annotation.AnnotationParser;
  42 import java.lang.annotation.Annotation;
  43 import java.lang.annotation.AnnotationFormatError;
  44 import java.nio.ByteBuffer;
  45 import java.util.StringJoiner;
  46 
  47 /**
  48  * A {@code Method} provides information about, and access to, a single method
  49  * on a class or interface.  The reflected method may be a class method
  50  * or an instance method (including an abstract method).
  51  *
  52  * <p>A {@code Method} permits widening conversions to occur when matching the
  53  * actual parameters to invoke with the underlying method's formal
  54  * parameters, but it throws an {@code IllegalArgumentException} if a
  55  * narrowing conversion would occur.
  56  *
  57  * @see Member
  58  * @see java.lang.Class
  59  * @see java.lang.Class#getMethods()
  60  * @see java.lang.Class#getMethod(String, Class[])
  61  * @see java.lang.Class#getDeclaredMethods()
  62  * @see java.lang.Class#getDeclaredMethod(String, Class[])
  63  *
  64  * @author Kenneth Russell
  65  * @author Nakul Saraiya
  66  * @since 1.1
  67  */
  68 public final class Method extends Executable {
  69     private Class<?>            clazz;
  70     private int                 slot;
  71     // This is guaranteed to be interned by the VM in the 1.4
  72     // reflection implementation
  73     private String              name;
  74     private Class<?>            returnType;
  75     private Class<?>[]          parameterTypes;
  76     private Class<?>[]          exceptionTypes;
  77     private int                 modifiers;
  78     // Generics and annotations support
  79     private transient String              signature;
  80     // generic info repository; lazily initialized
  81     private transient MethodRepository genericInfo;
  82     private byte[]              annotations;
  83     private byte[]              parameterAnnotations;
  84     private byte[]              annotationDefault;
  85     private volatile MethodAccessor methodAccessor;
  86     // For sharing of MethodAccessors. This branching structure is
  87     // currently only two levels deep (i.e., one root Method and
  88     // potentially many Method objects pointing to it.)
  89     //
  90     // If this branching structure would ever contain cycles, deadlocks can
  91     // occur in annotation code.
  92     private Method              root;
  93 
  94     // Generics infrastructure
  95     private String getGenericSignature() {return signature;}
  96 
  97     // Accessor for factory
  98     private GenericsFactory getFactory() {
  99         // create scope and factory
 100         return CoreReflectionFactory.make(this, MethodScope.make(this));
 101     }
 102 
 103     // Accessor for generic info repository
 104     @Override
 105     MethodRepository getGenericInfo() {
 106         // lazily initialize repository if necessary
 107         if (genericInfo == null) {
 108             // create and cache generic info repository
 109             genericInfo = MethodRepository.make(getGenericSignature(),
 110                                                 getFactory());
 111         }
 112         return genericInfo; //return cached repository
 113     }
 114 
 115     /**
 116      * Package-private constructor used by ReflectAccess to enable
 117      * instantiation of these objects in Java code from the java.lang
 118      * package via sun.reflect.LangReflectAccess.
 119      */
 120     Method(Class<?> declaringClass,
 121            String name,
 122            Class<?>[] parameterTypes,
 123            Class<?> returnType,
 124            Class<?>[] checkedExceptions,
 125            int modifiers,
 126            int slot,
 127            String signature,
 128            byte[] annotations,
 129            byte[] parameterAnnotations,
 130            byte[] annotationDefault) {
 131         this.clazz = declaringClass;
 132         this.name = name;
 133         this.parameterTypes = parameterTypes;
 134         this.returnType = returnType;
 135         this.exceptionTypes = checkedExceptions;
 136         this.modifiers = modifiers;
 137         this.slot = slot;
 138         this.signature = signature;
 139         this.annotations = annotations;
 140         this.parameterAnnotations = parameterAnnotations;
 141         this.annotationDefault = annotationDefault;
 142     }
 143 
 144     /**
 145      * Package-private routine (exposed to java.lang.Class via
 146      * ReflectAccess) which returns a copy of this Method. The copy's
 147      * "root" field points to this Method.
 148      */
 149     Method copy() {
 150         // This routine enables sharing of MethodAccessor objects
 151         // among Method objects which refer to the same underlying
 152         // method in the VM. (All of this contortion is only necessary
 153         // because of the "accessibility" bit in AccessibleObject,
 154         // which implicitly requires that new java.lang.reflect
 155         // objects be fabricated for each reflective call on Class
 156         // objects.)
 157         if (this.root != null)
 158             throw new IllegalArgumentException("Can not copy a non-root Method");
 159 
 160         Method res = new Method(clazz, name, parameterTypes, returnType,
 161                                 exceptionTypes, modifiers, slot, signature,
 162                                 annotations, parameterAnnotations, annotationDefault);
 163         res.root = this;
 164         // Might as well eagerly propagate this if already present
 165         res.methodAccessor = methodAccessor;
 166         return res;
 167     }
 168 
 169     /**
 170      * Make a copy of a leaf method.
 171      */
 172     Method leafCopy() {
 173         if (this.root == null)
 174             throw new IllegalArgumentException("Can only leafCopy a non-root Method");
 175 
 176         Method res = new Method(clazz, name, parameterTypes, returnType,
 177                 exceptionTypes, modifiers, slot, signature,
 178                 annotations, parameterAnnotations, annotationDefault);
 179         res.root = root;
 180         res.methodAccessor = methodAccessor;
 181         return res;
 182     }
 183 
 184     /**
 185      * @throws InaccessibleObjectException {@inheritDoc}
 186      * @throws SecurityException {@inheritDoc}
 187      */
 188     @Override
 189     @CallerSensitive
 190     public void setAccessible(boolean flag) {
 191         AccessibleObject.checkPermission();
 192         if (flag) checkCanSetAccessible(Reflection.getCallerClass());
 193         setAccessible0(flag);
 194     }
 195 
 196     @Override
 197     void checkCanSetAccessible(Class<?> caller) {
 198         checkCanSetAccessible(caller, clazz);
 199     }
 200 
 201     @Override
 202     Method getRoot() {
 203         return root;
 204     }
 205 
 206     @Override
 207     boolean hasGenericInformation() {
 208         return (getGenericSignature() != null);
 209     }
 210 
 211     @Override
 212     byte[] getAnnotationBytes() {
 213         return annotations;
 214     }
 215 
 216     /**
 217      * Returns the {@code Class} object representing the class or interface
 218      * that declares the method represented by this object.
 219      *
 220      */
 221     @Override
 222     public Class<?> getDeclaringClass() {
 223         return clazz;
 224     }
 225 
 226     /**
 227      * Returns the name of the method represented by this {@code Method}
 228      * object, as a {@code String}.
 229      */
 230     @Override
 231     public String getName() {
 232         return name;
 233     }
 234 
 235     /**
 236      * {@inheritDoc}
 237      */
 238     @Override
 239     public int getModifiers() {
 240         return modifiers;
 241     }
 242 
 243     /**
 244      * {@inheritDoc}
 245      * @throws GenericSignatureFormatError {@inheritDoc}
 246      * @since 1.5
 247      */
 248     @Override
 249     @SuppressWarnings({"rawtypes", "unchecked"})
 250     public TypeVariable<Method>[] getTypeParameters() {
 251         if (getGenericSignature() != null)
 252             return (TypeVariable<Method>[])getGenericInfo().getTypeParameters();
 253         else
 254             return (TypeVariable<Method>[])new TypeVariable[0];
 255     }
 256 
 257     /**
 258      * Returns a {@code Class} object that represents the formal return type
 259      * of the method represented by this {@code Method} object.
 260      *
 261      * @return the return type for the method this object represents
 262      */
 263     public Class<?> getReturnType() {
 264         return returnType;
 265     }
 266 
 267     /**
 268      * Returns a {@code Type} object that represents the formal return
 269      * type of the method represented by this {@code Method} object.
 270      *
 271      * <p>If the return type is a parameterized type,
 272      * the {@code Type} object returned must accurately reflect
 273      * the actual type parameters used in the source code.
 274      *
 275      * <p>If the return type is a type variable or a parameterized type, it
 276      * is created. Otherwise, it is resolved.
 277      *
 278      * @return  a {@code Type} object that represents the formal return
 279      *     type of the underlying  method
 280      * @throws GenericSignatureFormatError
 281      *     if the generic method signature does not conform to the format
 282      *     specified in
 283      *     <cite>The Java&trade; Virtual Machine Specification</cite>
 284      * @throws TypeNotPresentException if the underlying method's
 285      *     return type refers to a non-existent type declaration
 286      * @throws MalformedParameterizedTypeException if the
 287      *     underlying method's return typed refers to a parameterized
 288      *     type that cannot be instantiated for any reason
 289      * @since 1.5
 290      */
 291     public Type getGenericReturnType() {
 292       if (getGenericSignature() != null) {
 293         return getGenericInfo().getReturnType();
 294       } else { return getReturnType();}
 295     }
 296 
 297     @Override
 298     Class<?>[] getSharedParameterTypes() {
 299         return parameterTypes;
 300     }
 301 
 302     @Override
 303     Class<?>[] getSharedExceptionTypes() {
 304         return exceptionTypes;
 305     }
 306 
 307     /**
 308      * {@inheritDoc}
 309      */
 310     @Override
 311     public Class<?>[] getParameterTypes() {
 312         return parameterTypes.clone();
 313     }
 314 
 315     /**
 316      * {@inheritDoc}
 317      * @since 1.8
 318      */
 319     public int getParameterCount() { return parameterTypes.length; }
 320 
 321 
 322     /**
 323      * {@inheritDoc}
 324      * @throws GenericSignatureFormatError {@inheritDoc}
 325      * @throws TypeNotPresentException {@inheritDoc}
 326      * @throws MalformedParameterizedTypeException {@inheritDoc}
 327      * @since 1.5
 328      */
 329     @Override
 330     public Type[] getGenericParameterTypes() {
 331         return super.getGenericParameterTypes();
 332     }
 333 
 334     /**
 335      * {@inheritDoc}
 336      */
 337     @Override
 338     public Class<?>[] getExceptionTypes() {
 339         return exceptionTypes.clone();
 340     }
 341 
 342     /**
 343      * {@inheritDoc}
 344      * @throws GenericSignatureFormatError {@inheritDoc}
 345      * @throws TypeNotPresentException {@inheritDoc}
 346      * @throws MalformedParameterizedTypeException {@inheritDoc}
 347      * @since 1.5
 348      */
 349     @Override
 350     public Type[] getGenericExceptionTypes() {
 351         return super.getGenericExceptionTypes();
 352     }
 353 
 354     /**
 355      * Compares this {@code Method} against the specified object.  Returns
 356      * true if the objects are the same.  Two {@code Methods} are the same if
 357      * they were declared by the same class and have the same name
 358      * and formal parameter types and return type.
 359      */
 360     public boolean equals(Object obj) {
 361         if (obj != null && obj instanceof Method) {
 362             Method other = (Method)obj;
 363             if ((getDeclaringClass() == other.getDeclaringClass())
 364                 && (getName() == other.getName())) {
 365                 if (!returnType.equals(other.getReturnType()))
 366                     return false;
 367                 return equalParamTypes(parameterTypes, other.parameterTypes);
 368             }
 369         }
 370         return false;
 371     }
 372 
 373     /**
 374      * Returns a hashcode for this {@code Method}.  The hashcode is computed
 375      * as the exclusive-or of the hashcodes for the underlying
 376      * method's declaring class name and the method's name.
 377      */
 378     public int hashCode() {
 379         return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
 380     }
 381 
 382     /**
 383      * Returns a string describing this {@code Method}.  The string is
 384      * formatted as the method access modifiers, if any, followed by
 385      * the method return type, followed by a space, followed by the
 386      * class declaring the method, followed by a period, followed by
 387      * the method name, followed by a parenthesized, comma-separated
 388      * list of the method's formal parameter types. If the method
 389      * throws checked exceptions, the parameter list is followed by a
 390      * space, followed by the word "{@code throws}" followed by a
 391      * comma-separated list of the thrown exception types.
 392      * For example:
 393      * <pre>
 394      *    public boolean java.lang.Object.equals(java.lang.Object)
 395      * </pre>
 396      *
 397      * <p>The access modifiers are placed in canonical order as
 398      * specified by "The Java Language Specification".  This is
 399      * {@code public}, {@code protected} or {@code private} first,
 400      * and then other modifiers in the following order:
 401      * {@code abstract}, {@code default}, {@code static}, {@code final},
 402      * {@code synchronized}, {@code native}, {@code strictfp}.
 403      *
 404      * @return a string describing this {@code Method}
 405      *
 406      * @jls 8.4.3 Method Modifiers
 407      * @jls 9.4   Method Declarations
 408      * @jls 9.6.1 Annotation Type Elements
 409      */
 410     public String toString() {
 411         return sharedToString(Modifier.methodModifiers(),
 412                               isDefault(),
 413                               parameterTypes,
 414                               exceptionTypes);
 415     }
 416 
 417     @Override
 418     void specificToStringHeader(StringBuilder sb) {
 419         sb.append(getReturnType().getTypeName()).append(' ');
 420         sb.append(getDeclaringClass().getTypeName()).append('.');
 421         sb.append(getName());
 422     }
 423 
 424     @Override
 425     String toShortString() {
 426         StringBuilder sb = new StringBuilder("method ");
 427         sb.append(getDeclaringClass().getTypeName()).append('.');
 428         sb.append(getName());
 429         sb.append('(');
 430         StringJoiner sj = new StringJoiner(",");
 431         for (Class<?> parameterType : getParameterTypes()) {
 432             sj.add(parameterType.getTypeName());
 433         }
 434         sb.append(sj);
 435         sb.append(')');
 436         return sb.toString();
 437     }
 438 
 439     /**
 440      * Returns a string describing this {@code Method}, including type
 441      * parameters.  The string is formatted as the method access
 442      * modifiers, if any, followed by an angle-bracketed
 443      * comma-separated list of the method's type parameters, if any,
 444      * including informative bounds of the type parameters, if any,
 445      * followed by the method's generic return type, followed by a
 446      * space, followed by the class declaring the method, followed by
 447      * a period, followed by the method name, followed by a
 448      * parenthesized, comma-separated list of the method's generic
 449      * formal parameter types.
 450      *
 451      * If this method was declared to take a variable number of
 452      * arguments, instead of denoting the last parameter as
 453      * "<code><i>Type</i>[]</code>", it is denoted as
 454      * "<code><i>Type</i>...</code>".
 455      *
 456      * A space is used to separate access modifiers from one another
 457      * and from the type parameters or return type.  If there are no
 458      * type parameters, the type parameter list is elided; if the type
 459      * parameter list is present, a space separates the list from the
 460      * class name.  If the method is declared to throw exceptions, the
 461      * parameter list is followed by a space, followed by the word
 462      * "{@code throws}" followed by a comma-separated list of the generic
 463      * thrown exception types.
 464      *
 465      * <p>The access modifiers are placed in canonical order as
 466      * specified by "The Java Language Specification".  This is
 467      * {@code public}, {@code protected} or {@code private} first,
 468      * and then other modifiers in the following order:
 469      * {@code abstract}, {@code default}, {@code static}, {@code final},
 470      * {@code synchronized}, {@code native}, {@code strictfp}.
 471      *
 472      * @return a string describing this {@code Method},
 473      * include type parameters
 474      *
 475      * @since 1.5
 476      *
 477      * @jls 8.4.3 Method Modifiers
 478      * @jls 9.4   Method Declarations
 479      * @jls 9.6.1 Annotation Type Elements
 480      */
 481     @Override
 482     public String toGenericString() {
 483         return sharedToGenericString(Modifier.methodModifiers(), isDefault());
 484     }
 485 
 486     @Override
 487     void specificToGenericStringHeader(StringBuilder sb) {
 488         Type genRetType = getGenericReturnType();
 489         sb.append(genRetType.getTypeName()).append(' ');
 490         sb.append(getDeclaringClass().getTypeName()).append('.');
 491         sb.append(getName());
 492     }
 493 
 494     /**
 495      * Invokes the underlying method represented by this {@code Method}
 496      * object, on the specified object with the specified parameters.
 497      * Individual parameters are automatically unwrapped to match
 498      * primitive formal parameters, and both primitive and reference
 499      * parameters are subject to method invocation conversions as
 500      * necessary.
 501      *
 502      * <p>If the underlying method is static, then the specified {@code obj}
 503      * argument is ignored. It may be null.
 504      *
 505      * <p>If the number of formal parameters required by the underlying method is
 506      * 0, the supplied {@code args} array may be of length 0 or null.
 507      *
 508      * <p>If the underlying method is an instance method, it is invoked
 509      * using dynamic method lookup as documented in The Java Language
 510      * Specification, section 15.12.4.4; in particular,
 511      * overriding based on the runtime type of the target object may occur.
 512      *
 513      * <p>If the underlying method is static, the class that declared
 514      * the method is initialized if it has not already been initialized.
 515      *
 516      * <p>If the method completes normally, the value it returns is
 517      * returned to the caller of invoke; if the value has a primitive
 518      * type, it is first appropriately wrapped in an object. However,
 519      * if the value has the type of an array of a primitive type, the
 520      * elements of the array are <i>not</i> wrapped in objects; in
 521      * other words, an array of primitive type is returned.  If the
 522      * underlying method return type is void, the invocation returns
 523      * null.
 524      *
 525      * @param obj  the object the underlying method is invoked from
 526      * @param args the arguments used for the method call
 527      * @return the result of dispatching the method represented by
 528      * this object on {@code obj} with parameters
 529      * {@code args}
 530      *
 531      * @exception IllegalAccessException    if this {@code Method} object
 532      *              is enforcing Java language access control and the underlying
 533      *              method is inaccessible.
 534      * @exception IllegalArgumentException  if the method is an
 535      *              instance method and the specified object argument
 536      *              is not an instance of the class or interface
 537      *              declaring the underlying method (or of a subclass
 538      *              or implementor thereof); if the number of actual
 539      *              and formal parameters differ; if an unwrapping
 540      *              conversion for primitive arguments fails; or if,
 541      *              after possible unwrapping, a parameter value
 542      *              cannot be converted to the corresponding formal
 543      *              parameter type by a method invocation conversion.
 544      * @exception InvocationTargetException if the underlying method
 545      *              throws an exception.
 546      * @exception NullPointerException      if the specified object is null
 547      *              and the method is an instance method.
 548      * @exception ExceptionInInitializerError if the initialization
 549      * provoked by this method fails.
 550      */
 551     @CallerSensitive
 552     @ForceInline // to ensure Reflection.getCallerClass optimization
 553     @HotSpotIntrinsicCandidate
 554     public Object invoke(Object obj, Object... args)
 555         throws IllegalAccessException, IllegalArgumentException,
 556            InvocationTargetException
 557     {
 558         if (!override) {
 559             Class<?> caller = Reflection.getCallerClass();
 560             checkAccess(caller, clazz,
 561                         Modifier.isStatic(modifiers) ? null : obj.getClass(),
 562                         modifiers);
 563         }
 564         MethodAccessor ma = methodAccessor;             // read volatile
 565         if (ma == null) {
 566             ma = acquireMethodAccessor();
 567         }
 568         return ma.invoke(obj, args);
 569     }
 570 
 571     /**
 572      * Returns {@code true} if this method is a bridge
 573      * method; returns {@code false} otherwise.
 574      *
 575      * @return true if and only if this method is a bridge
 576      * method as defined by the Java Language Specification.
 577      * @since 1.5
 578      */
 579     public boolean isBridge() {
 580         return (getModifiers() & Modifier.BRIDGE) != 0;
 581     }
 582 
 583     /**
 584      * {@inheritDoc}
 585      * @since 1.5
 586      */
 587     @Override
 588     public boolean isVarArgs() {
 589         return super.isVarArgs();
 590     }
 591 
 592     /**
 593      * {@inheritDoc}
 594      * @jls 13.1 The Form of a Binary
 595      * @since 1.5
 596      */
 597     @Override
 598     public boolean isSynthetic() {
 599         return super.isSynthetic();
 600     }
 601 
 602     /**
 603      * Returns {@code true} if this method is a default
 604      * method; returns {@code false} otherwise.
 605      *
 606      * A default method is a public non-abstract instance method, that
 607      * is, a non-static method with a body, declared in an interface
 608      * type.
 609      *
 610      * @return true if and only if this method is a default
 611      * method as defined by the Java Language Specification.
 612      * @since 1.8
 613      */
 614     public boolean isDefault() {
 615         // Default methods are public non-abstract instance methods
 616         // declared in an interface.
 617         return ((getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) ==
 618                 Modifier.PUBLIC) && getDeclaringClass().isInterface();
 619     }
 620 
 621     // NOTE that there is no synchronization used here. It is correct
 622     // (though not efficient) to generate more than one MethodAccessor
 623     // for a given Method. However, avoiding synchronization will
 624     // probably make the implementation more scalable.
 625     private MethodAccessor acquireMethodAccessor() {
 626         // First check to see if one has been created yet, and take it
 627         // if so
 628         MethodAccessor tmp = null;
 629         if (root != null) tmp = root.getMethodAccessor();
 630         if (tmp != null) {
 631             methodAccessor = tmp;
 632         } else {
 633             // Otherwise fabricate one and propagate it up to the root
 634             tmp = reflectionFactory.newMethodAccessor(this);
 635             setMethodAccessor(tmp);
 636         }
 637 
 638         return tmp;
 639     }
 640 
 641     // Returns MethodAccessor for this Method object, not looking up
 642     // the chain to the root
 643     MethodAccessor getMethodAccessor() {
 644         return methodAccessor;
 645     }
 646 
 647     // Sets the MethodAccessor for this Method object and
 648     // (recursively) its root
 649     void setMethodAccessor(MethodAccessor accessor) {
 650         methodAccessor = accessor;
 651         // Propagate up
 652         if (root != null) {
 653             root.setMethodAccessor(accessor);
 654         }
 655     }
 656 
 657     /**
 658      * Returns the default value for the annotation member represented by
 659      * this {@code Method} instance.  If the member is of a primitive type,
 660      * an instance of the corresponding wrapper type is returned. Returns
 661      * null if no default is associated with the member, or if the method
 662      * instance does not represent a declared member of an annotation type.
 663      *
 664      * @return the default value for the annotation member represented
 665      *     by this {@code Method} instance.
 666      * @throws TypeNotPresentException if the annotation is of type
 667      *     {@link Class} and no definition can be found for the
 668      *     default class value.
 669      * @since  1.5
 670      */
 671     public Object getDefaultValue() {
 672         if  (annotationDefault == null)
 673             return null;
 674         Class<?> memberType = AnnotationType.invocationHandlerReturnType(
 675             getReturnType());
 676         Object result = AnnotationParser.parseMemberValue(
 677             memberType, ByteBuffer.wrap(annotationDefault),
 678             SharedSecrets.getJavaLangAccess().
 679                 getConstantPool(getDeclaringClass()),
 680             getDeclaringClass());
 681         if (result instanceof ExceptionProxy) {
 682             if (result instanceof TypeNotPresentExceptionProxy) {
 683                 TypeNotPresentExceptionProxy proxy = (TypeNotPresentExceptionProxy)result;
 684                 throw new TypeNotPresentException(proxy.typeName(), proxy.getCause());
 685             }
 686             throw new AnnotationFormatError("Invalid default: " + this);
 687         }
 688         return result;
 689     }
 690 
 691     /**
 692      * {@inheritDoc}
 693      * @throws NullPointerException  {@inheritDoc}
 694      * @since 1.5
 695      */
 696     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 697         return super.getAnnotation(annotationClass);
 698     }
 699 
 700     /**
 701      * {@inheritDoc}
 702      * @since 1.5
 703      */
 704     public Annotation[] getDeclaredAnnotations()  {
 705         return super.getDeclaredAnnotations();
 706     }
 707 
 708     /**
 709      * {@inheritDoc}
 710      * @since 1.5
 711      */
 712     @Override
 713     public Annotation[][] getParameterAnnotations() {
 714         return sharedGetParameterAnnotations(parameterTypes, parameterAnnotations);
 715     }
 716 
 717     /**
 718      * {@inheritDoc}
 719      * @since 1.8
 720      */
 721     @Override
 722     public AnnotatedType getAnnotatedReturnType() {
 723         return getAnnotatedReturnType0(getGenericReturnType());
 724     }
 725 
 726     @Override
 727     boolean handleParameterNumberMismatch(int resultLength, int numParameters) {
 728         throw new AnnotationFormatError("Parameter annotations don't match number of parameters");
 729     }
 730 }