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.misc.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     /**
 202      * Used by Excecutable for annotation sharing.
 203      */
 204     @Override
 205     Executable getRoot() {
 206         return root;
 207     }
 208 
 209     @Override
 210     boolean hasGenericInformation() {
 211         return (getGenericSignature() != null);
 212     }
 213 
 214     @Override
 215     byte[] getAnnotationBytes() {
 216         return annotations;
 217     }
 218 
 219     /**
 220      * Returns the {@code Class} object representing the class or interface
 221      * that declares the method represented by this object.
 222      */
 223     @Override
 224     public Class<?> getDeclaringClass() {
 225         return clazz;
 226     }
 227 
 228     /**
 229      * Returns the name of the method represented by this {@code Method}
 230      * object, as a {@code String}.
 231      */
 232     @Override
 233     public String getName() {
 234         return name;
 235     }
 236 
 237     /**
 238      * {@inheritDoc}
 239      */
 240     @Override
 241     public int getModifiers() {
 242         return modifiers;
 243     }
 244 
 245     /**
 246      * {@inheritDoc}
 247      * @throws GenericSignatureFormatError {@inheritDoc}
 248      * @since 1.5
 249      */
 250     @Override
 251     @SuppressWarnings({"rawtypes", "unchecked"})
 252     public TypeVariable<Method>[] getTypeParameters() {
 253         if (getGenericSignature() != null)
 254             return (TypeVariable<Method>[])getGenericInfo().getTypeParameters();
 255         else
 256             return (TypeVariable<Method>[])new TypeVariable[0];
 257     }
 258 
 259     /**
 260      * Returns a {@code Class} object that represents the formal return type
 261      * of the method represented by this {@code Method} object.
 262      *
 263      * @return the return type for the method this object represents
 264      */
 265     public Class<?> getReturnType() {
 266         return returnType;
 267     }
 268 
 269     /**
 270      * Returns a {@code Type} object that represents the formal return
 271      * type of the method represented by this {@code Method} object.
 272      *
 273      * <p>If the return type is a parameterized type,
 274      * the {@code Type} object returned must accurately reflect
 275      * the actual type parameters used in the source code.
 276      *
 277      * <p>If the return type is a type variable or a parameterized type, it
 278      * is created. Otherwise, it is resolved.
 279      *
 280      * @return  a {@code Type} object that represents the formal return
 281      *     type of the underlying  method
 282      * @throws GenericSignatureFormatError
 283      *     if the generic method signature does not conform to the format
 284      *     specified in
 285      *     <cite>The Java&trade; Virtual Machine Specification</cite>
 286      * @throws TypeNotPresentException if the underlying method's
 287      *     return type refers to a non-existent type declaration
 288      * @throws MalformedParameterizedTypeException if the
 289      *     underlying method's return typed refers to a parameterized
 290      *     type that cannot be instantiated for any reason
 291      * @since 1.5
 292      */
 293     public Type getGenericReturnType() {
 294       if (getGenericSignature() != null) {
 295         return getGenericInfo().getReturnType();
 296       } else { return getReturnType();}
 297     }
 298 
 299     @Override
 300     Class<?>[] getSharedParameterTypes() {
 301         return parameterTypes;
 302     }
 303 
 304     @Override
 305     Class<?>[] getSharedExceptionTypes() {
 306         return exceptionTypes;
 307     }
 308 
 309     /**
 310      * {@inheritDoc}
 311      */
 312     @Override
 313     public Class<?>[] getParameterTypes() {
 314         return parameterTypes.clone();
 315     }
 316 
 317     /**
 318      * {@inheritDoc}
 319      * @since 1.8
 320      */
 321     public int getParameterCount() { return parameterTypes.length; }
 322 
 323 
 324     /**
 325      * {@inheritDoc}
 326      * @throws GenericSignatureFormatError {@inheritDoc}
 327      * @throws TypeNotPresentException {@inheritDoc}
 328      * @throws MalformedParameterizedTypeException {@inheritDoc}
 329      * @since 1.5
 330      */
 331     @Override
 332     public Type[] getGenericParameterTypes() {
 333         return super.getGenericParameterTypes();
 334     }
 335 
 336     /**
 337      * {@inheritDoc}
 338      */
 339     @Override
 340     public Class<?>[] getExceptionTypes() {
 341         return exceptionTypes.clone();
 342     }
 343 
 344     /**
 345      * {@inheritDoc}
 346      * @throws GenericSignatureFormatError {@inheritDoc}
 347      * @throws TypeNotPresentException {@inheritDoc}
 348      * @throws MalformedParameterizedTypeException {@inheritDoc}
 349      * @since 1.5
 350      */
 351     @Override
 352     public Type[] getGenericExceptionTypes() {
 353         return super.getGenericExceptionTypes();
 354     }
 355 
 356     /**
 357      * Compares this {@code Method} against the specified object.  Returns
 358      * true if the objects are the same.  Two {@code Methods} are the same if
 359      * they were declared by the same class and have the same name
 360      * and formal parameter types and return type.
 361      */
 362     public boolean equals(Object obj) {
 363         if (obj != null && obj instanceof Method) {
 364             Method other = (Method)obj;
 365             if ((getDeclaringClass() == other.getDeclaringClass())
 366                 && (getName() == other.getName())) {
 367                 if (!returnType.equals(other.getReturnType()))
 368                     return false;
 369                 return equalParamTypes(parameterTypes, other.parameterTypes);
 370             }
 371         }
 372         return false;
 373     }
 374 
 375     /**
 376      * Returns a hashcode for this {@code Method}.  The hashcode is computed
 377      * as the exclusive-or of the hashcodes for the underlying
 378      * method's declaring class name and the method's name.
 379      */
 380     public int hashCode() {
 381         return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
 382     }
 383 
 384     /**
 385      * Returns a string describing this {@code Method}.  The string is
 386      * formatted as the method access modifiers, if any, followed by
 387      * the method return type, followed by a space, followed by the
 388      * class declaring the method, followed by a period, followed by
 389      * the method name, followed by a parenthesized, comma-separated
 390      * list of the method's formal parameter types. If the method
 391      * throws checked exceptions, the parameter list is followed by a
 392      * space, followed by the word "{@code throws}" followed by a
 393      * comma-separated list of the thrown exception types.
 394      * For example:
 395      * <pre>
 396      *    public boolean java.lang.Object.equals(java.lang.Object)
 397      * </pre>
 398      *
 399      * <p>The access modifiers are placed in canonical order as
 400      * specified by "The Java Language Specification".  This is
 401      * {@code public}, {@code protected} or {@code private} first,
 402      * and then other modifiers in the following order:
 403      * {@code abstract}, {@code default}, {@code static}, {@code final},
 404      * {@code synchronized}, {@code native}, {@code strictfp}.
 405      *
 406      * @return a string describing this {@code Method}
 407      *
 408      * @jls 8.4.3 Method Modifiers
 409      * @jls 9.4   Method Declarations
 410      * @jls 9.6.1 Annotation Type Elements
 411      */
 412     public String toString() {
 413         return sharedToString(Modifier.methodModifiers(),
 414                               isDefault(),
 415                               parameterTypes,
 416                               exceptionTypes);
 417     }
 418 
 419     @Override
 420     void specificToStringHeader(StringBuilder sb) {
 421         sb.append(getReturnType().getTypeName()).append(' ');
 422         sb.append(getDeclaringClass().getTypeName()).append('.');
 423         sb.append(getName());
 424     }
 425 
 426     @Override
 427     String toShortString() {
 428         StringBuilder sb = new StringBuilder("method ");
 429         sb.append(getDeclaringClass().getTypeName()).append('.');
 430         sb.append(getName());
 431         sb.append('(');
 432         StringJoiner sj = new StringJoiner(",");
 433         for (Class<?> parameterType : getParameterTypes()) {
 434             sj.add(parameterType.getTypeName());
 435         }
 436         sb.append(sj);
 437         sb.append(')');
 438         return sb.toString();
 439     }
 440 
 441     /**
 442      * Returns a string describing this {@code Method}, including
 443      * type parameters.  The string is formatted as the method access
 444      * modifiers, if any, followed by an angle-bracketed
 445      * comma-separated list of the method's 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 }