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