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