1 /* 2 * Copyright (c) 2012, 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 java.lang.annotation.*; 29 import java.util.Map; 30 import java.util.Objects; 31 import java.util.StringJoiner; 32 33 import jdk.internal.misc.SharedSecrets; 34 import sun.reflect.annotation.AnnotationParser; 35 import sun.reflect.annotation.AnnotationSupport; 36 import sun.reflect.annotation.TypeAnnotationParser; 37 import sun.reflect.annotation.TypeAnnotation; 38 import sun.reflect.generics.repository.ConstructorRepository; 39 40 /** 41 * A shared superclass for the common functionality of {@link Method} 42 * and {@link Constructor}. 43 * 44 * @since 1.8 45 */ 46 public abstract class Executable extends AccessibleObject 47 implements Member, GenericDeclaration { 48 /* 49 * Only grant package-visibility to the constructor. 50 */ 51 Executable() {} 52 53 /** 54 * Accessor method to allow code sharing 55 */ 56 abstract byte[] getAnnotationBytes(); 57 58 /** 59 * Accessor method to allow code sharing 60 */ 61 abstract Executable getRoot(); 62 63 /** 64 * Does the Executable have generic information. 65 */ 66 abstract boolean hasGenericInformation(); 67 68 abstract ConstructorRepository getGenericInfo(); 69 70 boolean equalParamTypes(Class<?>[] params1, Class<?>[] params2) { 71 /* Avoid unnecessary cloning */ 72 if (params1.length == params2.length) { 73 for (int i = 0; i < params1.length; i++) { 74 if (params1[i] != params2[i]) 75 return false; 76 } 77 return true; 78 } 79 return false; 80 } 81 82 Annotation[][] parseParameterAnnotations(byte[] parameterAnnotations) { 83 return AnnotationParser.parseParameterAnnotations( 84 parameterAnnotations, 85 SharedSecrets.getJavaLangAccess(). 86 getConstantPool(getDeclaringClass()), 87 getDeclaringClass()); 88 } 89 90 void printModifiersIfNonzero(StringBuilder sb, int mask, boolean isDefault) { 91 int mod = getModifiers() & mask; 92 93 if (mod != 0 && !isDefault) { 94 sb.append(Modifier.toString(mod)).append(' '); 95 } else { 96 int access_mod = mod & Modifier.ACCESS_MODIFIERS; 97 if (access_mod != 0) 98 sb.append(Modifier.toString(access_mod)).append(' '); 99 if (isDefault) 100 sb.append("default "); 101 mod = (mod & ~Modifier.ACCESS_MODIFIERS); 102 if (mod != 0) 103 sb.append(Modifier.toString(mod)).append(' '); 104 } 105 } 106 107 String sharedToString(int modifierMask, 108 boolean isDefault, 109 Class<?>[] parameterTypes, 110 Class<?>[] exceptionTypes) { 111 try { 112 StringBuilder sb = new StringBuilder(); 113 114 printModifiersIfNonzero(sb, modifierMask, isDefault); 115 specificToStringHeader(sb); 116 sb.append('('); 117 StringJoiner sj = new StringJoiner(","); 118 for (Class<?> parameterType : parameterTypes) { 119 sj.add(parameterType.getTypeName()); 120 } 121 sb.append(sj.toString()); 122 sb.append(')'); 123 124 if (exceptionTypes.length > 0) { 125 StringJoiner joiner = new StringJoiner(",", " throws ", ""); 126 for (Class<?> exceptionType : exceptionTypes) { 127 joiner.add(exceptionType.getTypeName()); 128 } 129 sb.append(joiner.toString()); 130 } 131 return sb.toString(); 132 } catch (Exception e) { 133 return "<" + e + ">"; 134 } 135 } 136 137 /** 138 * Generate toString header information specific to a method or 139 * constructor. 140 */ 141 abstract void specificToStringHeader(StringBuilder sb); 142 143 String sharedToGenericString(int modifierMask, boolean isDefault) { 144 try { 145 StringBuilder sb = new StringBuilder(); 146 147 printModifiersIfNonzero(sb, modifierMask, isDefault); 148 149 TypeVariable<?>[] typeparms = getTypeParameters(); 150 if (typeparms.length > 0) { 151 StringJoiner sj = new StringJoiner(",", "<", "> "); 152 for(TypeVariable<?> typeparm: typeparms) { 153 sj.add(typeparm.getTypeName()); 154 } 155 sb.append(sj.toString()); 156 } 157 158 specificToGenericStringHeader(sb); 159 160 sb.append('('); 161 StringJoiner sj = new StringJoiner(","); 162 Type[] params = getGenericParameterTypes(); 163 for (int j = 0; j < params.length; j++) { 164 String param = params[j].getTypeName(); 165 if (isVarArgs() && (j == params.length - 1)) // replace T[] with T... 166 param = param.replaceFirst("\\[\\]$", "..."); 167 sj.add(param); 168 } 169 sb.append(sj.toString()); 170 sb.append(')'); 171 172 Type[] exceptionTypes = getGenericExceptionTypes(); 173 if (exceptionTypes.length > 0) { 174 StringJoiner joiner = new StringJoiner(",", " throws ", ""); 175 for (Type exceptionType : exceptionTypes) { 176 joiner.add(exceptionType.getTypeName()); 177 } 178 sb.append(joiner.toString()); 179 } 180 return sb.toString(); 181 } catch (Exception e) { 182 return "<" + e + ">"; 183 } 184 } 185 186 /** 187 * Generate toGenericString header information specific to a 188 * method or constructor. 189 */ 190 abstract void specificToGenericStringHeader(StringBuilder sb); 191 192 /** 193 * Returns the {@code Class} object representing the class or interface 194 * that declares the executable represented by this object. 195 */ 196 public abstract Class<?> getDeclaringClass(); 197 198 /** 199 * Returns the name of the executable represented by this object. 200 */ 201 public abstract String getName(); 202 203 /** 204 * Returns the Java language {@linkplain Modifier modifiers} for 205 * the executable represented by this object. 206 */ 207 public abstract int getModifiers(); 208 209 /** 210 * Returns an array of {@code TypeVariable} objects that represent the 211 * type variables declared by the generic declaration represented by this 212 * {@code GenericDeclaration} object, in declaration order. Returns an 213 * array of length 0 if the underlying generic declaration declares no type 214 * variables. 215 * 216 * @return an array of {@code TypeVariable} objects that represent 217 * the type variables declared by this generic declaration 218 * @throws GenericSignatureFormatError if the generic 219 * signature of this generic declaration does not conform to 220 * the format specified in 221 * <cite>The Java™ Virtual Machine Specification</cite> 222 */ 223 public abstract TypeVariable<?>[] getTypeParameters(); 224 225 /** 226 * Returns an array of {@code Class} objects that represent the formal 227 * parameter types, in declaration order, of the executable 228 * represented by this object. Returns an array of length 229 * 0 if the underlying executable takes no parameters. 230 * 231 * @return the parameter types for the executable this object 232 * represents 233 */ 234 public abstract Class<?>[] getParameterTypes(); 235 236 /** 237 * Returns the number of formal parameters (whether explicitly 238 * declared or implicitly declared or neither) for the executable 239 * represented by this object. 240 * 241 * @return The number of formal parameters for the executable this 242 * object represents 243 */ 244 public int getParameterCount() { 245 throw new AbstractMethodError(); 246 } 247 248 /** 249 * Returns an array of {@code Type} objects that represent the formal 250 * parameter types, in declaration order, of the executable represented by 251 * this object. Returns an array of length 0 if the 252 * underlying executable takes no parameters. 253 * 254 * <p>If a formal parameter type is a parameterized type, 255 * the {@code Type} object returned for it must accurately reflect 256 * the actual type parameters used in the source code. 257 * 258 * <p>If a formal parameter type is a type variable or a parameterized 259 * type, it is created. Otherwise, it is resolved. 260 * 261 * @return an array of {@code Type}s that represent the formal 262 * parameter types of the underlying executable, in declaration order 263 * @throws GenericSignatureFormatError 264 * if the generic method signature does not conform to the format 265 * specified in 266 * <cite>The Java™ Virtual Machine Specification</cite> 267 * @throws TypeNotPresentException if any of the parameter 268 * types of the underlying executable refers to a non-existent type 269 * declaration 270 * @throws MalformedParameterizedTypeException if any of 271 * the underlying executable's parameter types refer to a parameterized 272 * type that cannot be instantiated for any reason 273 */ 274 public Type[] getGenericParameterTypes() { 275 if (hasGenericInformation()) 276 return getGenericInfo().getParameterTypes(); 277 else 278 return getParameterTypes(); 279 } 280 281 /** 282 * Behaves like {@code getGenericParameterTypes}, but returns type 283 * information for all parameters, including synthetic parameters. 284 */ 285 Type[] getAllGenericParameterTypes() { 286 final boolean genericInfo = hasGenericInformation(); 287 288 // Easy case: we don't have generic parameter information. In 289 // this case, we just return the result of 290 // getParameterTypes(). 291 if (!genericInfo) { 292 return getParameterTypes(); 293 } else { 294 final boolean realParamData = hasRealParameterData(); 295 final Type[] genericParamTypes = getGenericParameterTypes(); 296 final Type[] nonGenericParamTypes = getParameterTypes(); 297 final Type[] out = new Type[nonGenericParamTypes.length]; 298 final Parameter[] params = getParameters(); 299 int fromidx = 0; 300 // If we have real parameter data, then we use the 301 // synthetic and mandate flags to our advantage. 302 if (realParamData) { 303 for (int i = 0; i < out.length; i++) { 304 final Parameter param = params[i]; 305 if (param.isSynthetic() || param.isImplicit()) { 306 // If we hit a synthetic or mandated parameter, 307 // use the non generic parameter info. 308 out[i] = nonGenericParamTypes[i]; 309 } else { 310 // Otherwise, use the generic parameter info. 311 out[i] = genericParamTypes[fromidx]; 312 fromidx++; 313 } 314 } 315 } else { 316 // Otherwise, use the non-generic parameter data. 317 // Without method parameter reflection data, we have 318 // no way to figure out which parameters are 319 // synthetic/mandated, thus, no way to match up the 320 // indexes. 321 return genericParamTypes.length == nonGenericParamTypes.length ? 322 genericParamTypes : nonGenericParamTypes; 323 } 324 return out; 325 } 326 } 327 328 /** 329 * Returns an array of {@code Parameter} objects that represent 330 * all the parameters to the underlying executable represented by 331 * this object. Returns an array of length 0 if the executable 332 * has no parameters. 333 * 334 * <p>The parameters of the underlying executable do not necessarily 335 * have unique names, or names that are legal identifiers in the 336 * Java programming language (JLS 3.8). 337 * 338 * @throws MalformedParametersException if the class file contains 339 * a MethodParameters attribute that is improperly formatted. 340 * @return an array of {@code Parameter} objects representing all 341 * the parameters to the executable this object represents. 342 */ 343 public Parameter[] getParameters() { 344 // TODO: This may eventually need to be guarded by security 345 // mechanisms similar to those in Field, Method, etc. 346 // 347 // Need to copy the cached array to prevent users from messing 348 // with it. Since parameters are immutable, we can 349 // shallow-copy. 350 return privateGetParameters().clone(); 351 } 352 353 private Parameter[] synthesizeAllParams() { 354 final int realparams = getParameterCount(); 355 final Parameter[] out = new Parameter[realparams]; 356 for (int i = 0; i < realparams; i++) 357 // TODO: is there a way to synthetically derive the 358 // modifiers? Probably not in the general case, since 359 // we'd have no way of knowing about them, but there 360 // may be specific cases. 361 out[i] = new Parameter("arg" + i, 0, this, i); 362 return out; 363 } 364 365 private void verifyParameters(final Parameter[] parameters) { 366 final int mask = Modifier.FINAL | Modifier.SYNTHETIC | Modifier.MANDATED; 367 368 if (getParameterTypes().length != parameters.length) 369 throw new MalformedParametersException("Wrong number of parameters in MethodParameters attribute"); 370 371 for (Parameter parameter : parameters) { 372 final String name = parameter.getRealName(); 373 final int mods = parameter.getModifiers(); 374 375 if (name != null) { 376 if (name.isEmpty() || name.indexOf('.') != -1 || 377 name.indexOf(';') != -1 || name.indexOf('[') != -1 || 378 name.indexOf('/') != -1) { 379 throw new MalformedParametersException("Invalid parameter name \"" + name + "\""); 380 } 381 } 382 383 if (mods != (mods & mask)) { 384 throw new MalformedParametersException("Invalid parameter modifiers"); 385 } 386 } 387 } 388 389 private Parameter[] privateGetParameters() { 390 // Use tmp to avoid multiple writes to a volatile. 391 Parameter[] tmp = parameters; 392 393 if (tmp == null) { 394 395 // Otherwise, go to the JVM to get them 396 try { 397 tmp = getParameters0(); 398 } catch(IllegalArgumentException e) { 399 // Rethrow ClassFormatErrors 400 throw new MalformedParametersException("Invalid constant pool index"); 401 } 402 403 // If we get back nothing, then synthesize parameters 404 if (tmp == null) { 405 hasRealParameterData = false; 406 tmp = synthesizeAllParams(); 407 } else { 408 hasRealParameterData = true; 409 verifyParameters(tmp); 410 } 411 412 parameters = tmp; 413 } 414 415 return tmp; 416 } 417 418 boolean hasRealParameterData() { 419 // If this somehow gets called before parameters gets 420 // initialized, force it into existence. 421 if (parameters == null) { 422 privateGetParameters(); 423 } 424 return hasRealParameterData; 425 } 426 427 private transient volatile boolean hasRealParameterData; 428 private transient volatile Parameter[] parameters; 429 430 private native Parameter[] getParameters0(); 431 native byte[] getTypeAnnotationBytes0(); 432 433 // Needed by reflectaccess 434 byte[] getTypeAnnotationBytes() { 435 return getTypeAnnotationBytes0(); 436 } 437 438 /** 439 * Returns an array of {@code Class} objects that represent the 440 * types of exceptions declared to be thrown by the underlying 441 * executable represented by this object. Returns an array of 442 * length 0 if the executable declares no exceptions in its {@code 443 * throws} clause. 444 * 445 * @return the exception types declared as being thrown by the 446 * executable this object represents 447 */ 448 public abstract Class<?>[] getExceptionTypes(); 449 450 /** 451 * Returns an array of {@code Type} objects that represent the 452 * exceptions declared to be thrown by this executable object. 453 * Returns an array of length 0 if the underlying executable declares 454 * no exceptions in its {@code throws} clause. 455 * 456 * <p>If an exception type is a type variable or a parameterized 457 * type, it is created. Otherwise, it is resolved. 458 * 459 * @return an array of Types that represent the exception types 460 * thrown by the underlying executable 461 * @throws GenericSignatureFormatError 462 * if the generic method signature does not conform to the format 463 * specified in 464 * <cite>The Java™ Virtual Machine Specification</cite> 465 * @throws TypeNotPresentException if the underlying executable's 466 * {@code throws} clause refers to a non-existent type declaration 467 * @throws MalformedParameterizedTypeException if 468 * the underlying executable's {@code throws} clause refers to a 469 * parameterized type that cannot be instantiated for any reason 470 */ 471 public Type[] getGenericExceptionTypes() { 472 Type[] result; 473 if (hasGenericInformation() && 474 ((result = getGenericInfo().getExceptionTypes()).length > 0)) 475 return result; 476 else 477 return getExceptionTypes(); 478 } 479 480 /** 481 * Returns a string describing this {@code Executable}, including 482 * any type parameters. 483 * @return a string describing this {@code Executable}, including 484 * any type parameters 485 */ 486 public abstract String toGenericString(); 487 488 /** 489 * Returns {@code true} if this executable was declared to take a 490 * variable number of arguments; returns {@code false} otherwise. 491 * 492 * @return {@code true} if an only if this executable was declared 493 * to take a variable number of arguments. 494 */ 495 public boolean isVarArgs() { 496 return (getModifiers() & Modifier.VARARGS) != 0; 497 } 498 499 /** 500 * Returns {@code true} if this executable is a synthetic 501 * construct; returns {@code false} otherwise. 502 * 503 * @return true if and only if this executable is a synthetic 504 * construct as defined by 505 * <cite>The Java™ Language Specification</cite>. 506 * @jls 13.1 The Form of a Binary 507 */ 508 public boolean isSynthetic() { 509 return Modifier.isSynthetic(getModifiers()); 510 } 511 512 /** 513 * Returns an array of arrays of {@code Annotation}s that 514 * represent the annotations on the formal parameters, in 515 * declaration order, of the {@code Executable} represented by 516 * this object. Synthetic and mandated parameters (see 517 * explanation below), such as the outer "this" parameter to an 518 * inner class constructor will be represented in the returned 519 * array. If the executable has no parameters (meaning no formal, 520 * no synthetic, and no mandated parameters), a zero-length array 521 * will be returned. If the {@code Executable} has one or more 522 * parameters, a nested array of length zero is returned for each 523 * parameter with no annotations. The annotation objects contained 524 * in the returned arrays are serializable. The caller of this 525 * method is free to modify the returned arrays; it will have no 526 * effect on the arrays returned to other callers. 527 * 528 * A compiler may add extra parameters that are implicitly 529 * declared in source ("mandated"), as well as parameters that 530 * are neither implicitly nor explicitly declared in source 531 * ("synthetic") to the parameter list for a method. See {@link 532 * java.lang.reflect.Parameter} for more information. 533 * 534 * @see java.lang.reflect.Parameter 535 * @see java.lang.reflect.Parameter#getAnnotations 536 * @return an array of arrays that represent the annotations on 537 * the formal and implicit parameters, in declaration order, of 538 * the executable represented by this object 539 */ 540 public abstract Annotation[][] getParameterAnnotations(); 541 542 Annotation[][] sharedGetParameterAnnotations(Class<?>[] parameterTypes, 543 byte[] parameterAnnotations) { 544 int numParameters = parameterTypes.length; 545 if (parameterAnnotations == null) 546 return new Annotation[numParameters][0]; 547 548 Annotation[][] result = parseParameterAnnotations(parameterAnnotations); 549 550 if (result.length != numParameters) 551 handleParameterNumberMismatch(result.length, numParameters); 552 return result; 553 } 554 555 abstract void handleParameterNumberMismatch(int resultLength, int numParameters); 556 557 /** 558 * {@inheritDoc} 559 * @throws NullPointerException {@inheritDoc} 560 */ 561 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 562 Objects.requireNonNull(annotationClass); 563 return annotationClass.cast(declaredAnnotations().get(annotationClass)); 564 } 565 566 /** 567 * {@inheritDoc} 568 * @throws NullPointerException {@inheritDoc} 569 */ 570 @Override 571 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { 572 Objects.requireNonNull(annotationClass); 573 574 return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); 575 } 576 577 /** 578 * {@inheritDoc} 579 */ 580 public Annotation[] getDeclaredAnnotations() { 581 return AnnotationParser.toArray(declaredAnnotations()); 582 } 583 584 private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations; 585 586 private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { 587 Map<Class<? extends Annotation>, Annotation> declAnnos; 588 if ((declAnnos = declaredAnnotations) == null) { 589 synchronized (this) { 590 if ((declAnnos = declaredAnnotations) == null) { 591 Executable root = getRoot(); 592 if (root != null) { 593 declAnnos = root.declaredAnnotations(); 594 } else { 595 declAnnos = AnnotationParser.parseAnnotations( 596 getAnnotationBytes(), 597 SharedSecrets.getJavaLangAccess(). 598 getConstantPool(getDeclaringClass()), 599 getDeclaringClass() 600 ); 601 } 602 declaredAnnotations = declAnnos; 603 } 604 } 605 } 606 return declAnnos; 607 } 608 609 /** 610 * Returns an {@code AnnotatedType} object that represents the use of a type to 611 * specify the return type of the method/constructor represented by this 612 * Executable. 613 * 614 * If this {@code Executable} object represents a constructor, the {@code 615 * AnnotatedType} object represents the type of the constructed object. 616 * 617 * If this {@code Executable} object represents a method, the {@code 618 * AnnotatedType} object represents the use of a type to specify the return 619 * type of the method. 620 * 621 * @return an object representing the return type of the method 622 * or constructor represented by this {@code Executable} 623 */ 624 public abstract AnnotatedType getAnnotatedReturnType(); 625 626 /* Helper for subclasses of Executable. 627 * 628 * Returns an AnnotatedType object that represents the use of a type to 629 * specify the return type of the method/constructor represented by this 630 * Executable. 631 */ 632 AnnotatedType getAnnotatedReturnType0(Type returnType) { 633 return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(), 634 SharedSecrets.getJavaLangAccess(). 635 getConstantPool(getDeclaringClass()), 636 this, 637 getDeclaringClass(), 638 returnType, 639 TypeAnnotation.TypeAnnotationTarget.METHOD_RETURN); 640 } 641 642 /** 643 * Returns an {@code AnnotatedType} object that represents the use of a 644 * type to specify the receiver type of the method/constructor represented 645 * by this {@code Executable} object. 646 * 647 * The receiver type of a method/constructor is available only if the 648 * method/constructor has a receiver parameter (JLS 8.4.1). If this {@code 649 * Executable} object <em>represents an instance method or represents a 650 * constructor of an inner member class</em>, and the 651 * method/constructor <em>either</em> has no receiver parameter or has a 652 * receiver parameter with no annotations on its type, then the return 653 * value is an {@code AnnotatedType} object representing an element with no 654 * annotations. 655 * 656 * If this {@code Executable} object represents a static method or 657 * represents a constructor of a top level, static member, local, or 658 * anonymous class, then the return value is null. 659 * 660 * @return an object representing the receiver type of the method or 661 * constructor represented by this {@code Executable} or {@code null} if 662 * this {@code Executable} can not have a receiver parameter 663 */ 664 public AnnotatedType getAnnotatedReceiverType() { 665 if (Modifier.isStatic(this.getModifiers())) 666 return null; 667 return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(), 668 SharedSecrets.getJavaLangAccess(). 669 getConstantPool(getDeclaringClass()), 670 this, 671 getDeclaringClass(), 672 getDeclaringClass(), 673 TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER); 674 } 675 676 /** 677 * Returns an array of {@code AnnotatedType} objects that represent the use 678 * of types to specify formal parameter types of the method/constructor 679 * represented by this Executable. The order of the objects in the array 680 * corresponds to the order of the formal parameter types in the 681 * declaration of the method/constructor. 682 * 683 * Returns an array of length 0 if the method/constructor declares no 684 * parameters. 685 * 686 * @return an array of objects representing the types of the 687 * formal parameters of the method or constructor represented by this 688 * {@code Executable} 689 */ 690 public AnnotatedType[] getAnnotatedParameterTypes() { 691 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(), 692 SharedSecrets.getJavaLangAccess(). 693 getConstantPool(getDeclaringClass()), 694 this, 695 getDeclaringClass(), 696 getAllGenericParameterTypes(), 697 TypeAnnotation.TypeAnnotationTarget.METHOD_FORMAL_PARAMETER); 698 } 699 700 /** 701 * Returns an array of {@code AnnotatedType} objects that represent the use 702 * of types to specify the declared exceptions of the method/constructor 703 * represented by this Executable. The order of the objects in the array 704 * corresponds to the order of the exception types in the declaration of 705 * the method/constructor. 706 * 707 * Returns an array of length 0 if the method/constructor declares no 708 * exceptions. 709 * 710 * @return an array of objects representing the declared 711 * exceptions of the method or constructor represented by this {@code 712 * Executable} 713 */ 714 public AnnotatedType[] getAnnotatedExceptionTypes() { 715 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(), 716 SharedSecrets.getJavaLangAccess(). 717 getConstantPool(getDeclaringClass()), 718 this, 719 getDeclaringClass(), 720 getGenericExceptionTypes(), 721 TypeAnnotation.TypeAnnotationTarget.THROWS); 722 } 723 724 }