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 // returns shared array of parameter types - must never give it out 226 // to the untrusted code... 227 abstract Class<?>[] getSharedParameterTypes(); 228 229 /** 230 * Returns an array of {@code Class} objects that represent the formal 231 * parameter types, in declaration order, of the executable 232 * represented by this object. Returns an array of length 233 * 0 if the underlying executable takes no parameters. 234 * 235 * @return the parameter types for the executable this object 236 * represents 237 */ 238 public abstract Class<?>[] getParameterTypes(); 239 240 /** 241 * Returns the number of formal parameters (whether explicitly 242 * declared or implicitly declared or neither) for the executable 243 * represented by this object. 244 * 245 * @return The number of formal parameters for the executable this 246 * object represents 247 */ 248 public int getParameterCount() { 249 throw new AbstractMethodError(); 250 } 251 252 /** 253 * Returns an array of {@code Type} objects that represent the formal 254 * parameter types, in declaration order, of the executable represented by 255 * this object. Returns an array of length 0 if the 256 * underlying executable takes no parameters. 257 * 258 * <p>If a formal parameter type is a parameterized type, 259 * the {@code Type} object returned for it must accurately reflect 260 * the actual type parameters used in the source code. 261 * 262 * <p>If a formal parameter type is a type variable or a parameterized 263 * type, it is created. Otherwise, it is resolved. 264 * 265 * @return an array of {@code Type}s that represent the formal 266 * parameter types of the underlying executable, in declaration order 267 * @throws GenericSignatureFormatError 268 * if the generic method signature does not conform to the format 269 * specified in 270 * <cite>The Java™ Virtual Machine Specification</cite> 271 * @throws TypeNotPresentException if any of the parameter 272 * types of the underlying executable refers to a non-existent type 273 * declaration 274 * @throws MalformedParameterizedTypeException if any of 275 * the underlying executable's parameter types refer to a parameterized 276 * type that cannot be instantiated for any reason 277 */ 278 public Type[] getGenericParameterTypes() { 279 if (hasGenericInformation()) 280 return getGenericInfo().getParameterTypes(); 281 else 282 return getParameterTypes(); 283 } 284 285 /** 286 * Behaves like {@code getGenericParameterTypes}, but returns type 287 * information for all parameters, including synthetic parameters. 288 */ 289 Type[] getAllGenericParameterTypes() { 290 final boolean genericInfo = hasGenericInformation(); 291 292 // Easy case: we don't have generic parameter information. In 293 // this case, we just return the result of 294 // getParameterTypes(). 295 if (!genericInfo) { 296 return getParameterTypes(); 297 } else { 298 final boolean realParamData = hasRealParameterData(); 299 final Type[] genericParamTypes = getGenericParameterTypes(); 300 final Type[] nonGenericParamTypes = getParameterTypes(); 301 final Type[] out = new Type[nonGenericParamTypes.length]; 302 final Parameter[] params = getParameters(); 303 int fromidx = 0; 304 // If we have real parameter data, then we use the 305 // synthetic and mandate flags to our advantage. 306 if (realParamData) { 307 for (int i = 0; i < out.length; i++) { 308 final Parameter param = params[i]; 309 if (param.isSynthetic() || param.isImplicit()) { 310 // If we hit a synthetic or mandated parameter, 311 // use the non generic parameter info. 312 out[i] = nonGenericParamTypes[i]; 313 } else { 314 // Otherwise, use the generic parameter info. 315 out[i] = genericParamTypes[fromidx]; 316 fromidx++; 317 } 318 } 319 } else { 320 // Otherwise, use the non-generic parameter data. 321 // Without method parameter reflection data, we have 322 // no way to figure out which parameters are 323 // synthetic/mandated, thus, no way to match up the 324 // indexes. 325 return genericParamTypes.length == nonGenericParamTypes.length ? 326 genericParamTypes : nonGenericParamTypes; 327 } 328 return out; 329 } 330 } 331 332 /** 333 * Returns an array of {@code Parameter} objects that represent 334 * all the parameters to the underlying executable represented by 335 * this object. Returns an array of length 0 if the executable 336 * has no parameters. 337 * 338 * <p>The parameters of the underlying executable do not necessarily 339 * have unique names, or names that are legal identifiers in the 340 * Java programming language (JLS 3.8). 341 * 342 * @throws MalformedParametersException if the class file contains 343 * a MethodParameters attribute that is improperly formatted. 344 * @return an array of {@code Parameter} objects representing all 345 * the parameters to the executable this object represents. 346 */ 347 public Parameter[] getParameters() { 348 // TODO: This may eventually need to be guarded by security 349 // mechanisms similar to those in Field, Method, etc. 350 // 351 // Need to copy the cached array to prevent users from messing 352 // with it. Since parameters are immutable, we can 353 // shallow-copy. 354 return privateGetParameters().clone(); 355 } 356 357 private Parameter[] synthesizeAllParams() { 358 final int realparams = getParameterCount(); 359 final Parameter[] out = new Parameter[realparams]; 360 for (int i = 0; i < realparams; i++) 361 // TODO: is there a way to synthetically derive the 362 // modifiers? Probably not in the general case, since 363 // we'd have no way of knowing about them, but there 364 // may be specific cases. 365 out[i] = new Parameter("arg" + i, 0, this, i); 366 return out; 367 } 368 369 private void verifyParameters(final Parameter[] parameters) { 370 final int mask = Modifier.FINAL | Modifier.SYNTHETIC | Modifier.MANDATED; 371 372 if (getParameterTypes().length != parameters.length) 373 throw new MalformedParametersException("Wrong number of parameters in MethodParameters attribute"); 374 375 for (Parameter parameter : parameters) { 376 final String name = parameter.getRealName(); 377 final int mods = parameter.getModifiers(); 378 379 if (name != null) { 380 if (name.isEmpty() || name.indexOf('.') != -1 || 381 name.indexOf(';') != -1 || name.indexOf('[') != -1 || 382 name.indexOf('/') != -1) { 383 throw new MalformedParametersException("Invalid parameter name \"" + name + "\""); 384 } 385 } 386 387 if (mods != (mods & mask)) { 388 throw new MalformedParametersException("Invalid parameter modifiers"); 389 } 390 } 391 } 392 393 private Parameter[] privateGetParameters() { 394 // Use tmp to avoid multiple writes to a volatile. 395 Parameter[] tmp = parameters; 396 397 if (tmp == null) { 398 399 // Otherwise, go to the JVM to get them 400 try { 401 tmp = getParameters0(); 402 } catch(IllegalArgumentException e) { 403 // Rethrow ClassFormatErrors 404 throw new MalformedParametersException("Invalid constant pool index"); 405 } 406 407 // If we get back nothing, then synthesize parameters 408 if (tmp == null) { 409 hasRealParameterData = false; 410 tmp = synthesizeAllParams(); 411 } else { 412 hasRealParameterData = true; 413 verifyParameters(tmp); 414 } 415 416 parameters = tmp; 417 } 418 419 return tmp; 420 } 421 422 boolean hasRealParameterData() { 423 // If this somehow gets called before parameters gets 424 // initialized, force it into existence. 425 if (parameters == null) { 426 privateGetParameters(); 427 } 428 return hasRealParameterData; 429 } 430 431 private transient volatile boolean hasRealParameterData; 432 private transient volatile Parameter[] parameters; 433 434 private native Parameter[] getParameters0(); 435 native byte[] getTypeAnnotationBytes0(); 436 437 // Needed by reflectaccess 438 byte[] getTypeAnnotationBytes() { 439 return getTypeAnnotationBytes0(); 440 } 441 442 /** 443 * Returns an array of {@code Class} objects that represent the 444 * types of exceptions declared to be thrown by the underlying 445 * executable represented by this object. Returns an array of 446 * length 0 if the executable declares no exceptions in its {@code 447 * throws} clause. 448 * 449 * @return the exception types declared as being thrown by the 450 * executable this object represents 451 */ 452 public abstract Class<?>[] getExceptionTypes(); 453 454 /** 455 * Returns an array of {@code Type} objects that represent the 456 * exceptions declared to be thrown by this executable object. 457 * Returns an array of length 0 if the underlying executable declares 458 * no exceptions in its {@code throws} clause. 459 * 460 * <p>If an exception type is a type variable or a parameterized 461 * type, it is created. Otherwise, it is resolved. 462 * 463 * @return an array of Types that represent the exception types 464 * thrown by the underlying executable 465 * @throws GenericSignatureFormatError 466 * if the generic method signature does not conform to the format 467 * specified in 468 * <cite>The Java™ Virtual Machine Specification</cite> 469 * @throws TypeNotPresentException if the underlying executable's 470 * {@code throws} clause refers to a non-existent type declaration 471 * @throws MalformedParameterizedTypeException if 472 * the underlying executable's {@code throws} clause refers to a 473 * parameterized type that cannot be instantiated for any reason 474 */ 475 public Type[] getGenericExceptionTypes() { 476 Type[] result; 477 if (hasGenericInformation() && 478 ((result = getGenericInfo().getExceptionTypes()).length > 0)) 479 return result; 480 else 481 return getExceptionTypes(); 482 } 483 484 /** 485 * Returns a string describing this {@code Executable}, including 486 * any type parameters. 487 * @return a string describing this {@code Executable}, including 488 * any type parameters 489 */ 490 public abstract String toGenericString(); 491 492 /** 493 * Returns {@code true} if this executable was declared to take a 494 * variable number of arguments; returns {@code false} otherwise. 495 * 496 * @return {@code true} if an only if this executable was declared 497 * to take a variable number of arguments. 498 */ 499 public boolean isVarArgs() { 500 return (getModifiers() & Modifier.VARARGS) != 0; 501 } 502 503 /** 504 * Returns {@code true} if this executable is a synthetic 505 * construct; returns {@code false} otherwise. 506 * 507 * @return true if and only if this executable is a synthetic 508 * construct as defined by 509 * <cite>The Java™ Language Specification</cite>. 510 * @jls 13.1 The Form of a Binary 511 */ 512 public boolean isSynthetic() { 513 return Modifier.isSynthetic(getModifiers()); 514 } 515 516 /** 517 * Returns an array of arrays of {@code Annotation}s that 518 * represent the annotations on the formal parameters, in 519 * declaration order, of the {@code Executable} represented by 520 * this object. Synthetic and mandated parameters (see 521 * explanation below), such as the outer "this" parameter to an 522 * inner class constructor will be represented in the returned 523 * array. If the executable has no parameters (meaning no formal, 524 * no synthetic, and no mandated parameters), a zero-length array 525 * will be returned. If the {@code Executable} has one or more 526 * parameters, a nested array of length zero is returned for each 527 * parameter with no annotations. The annotation objects contained 528 * in the returned arrays are serializable. The caller of this 529 * method is free to modify the returned arrays; it will have no 530 * effect on the arrays returned to other callers. 531 * 532 * A compiler may add extra parameters that are implicitly 533 * declared in source ("mandated"), as well as parameters that 534 * are neither implicitly nor explicitly declared in source 535 * ("synthetic") to the parameter list for a method. See {@link 536 * java.lang.reflect.Parameter} for more information. 537 * 538 * @see java.lang.reflect.Parameter 539 * @see java.lang.reflect.Parameter#getAnnotations 540 * @return an array of arrays that represent the annotations on 541 * the formal and implicit parameters, in declaration order, of 542 * the executable represented by this object 543 */ 544 public abstract Annotation[][] getParameterAnnotations(); 545 546 Annotation[][] sharedGetParameterAnnotations(Class<?>[] parameterTypes, 547 byte[] parameterAnnotations) { 548 int numParameters = parameterTypes.length; 549 if (parameterAnnotations == null) 550 return new Annotation[numParameters][0]; 551 552 Annotation[][] result = parseParameterAnnotations(parameterAnnotations); 553 554 if (result.length != numParameters) 555 handleParameterNumberMismatch(result.length, numParameters); 556 return result; 557 } 558 559 abstract void handleParameterNumberMismatch(int resultLength, int numParameters); 560 561 /** 562 * {@inheritDoc} 563 * @throws NullPointerException {@inheritDoc} 564 */ 565 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 566 Objects.requireNonNull(annotationClass); 567 return annotationClass.cast(declaredAnnotations().get(annotationClass)); 568 } 569 570 /** 571 * {@inheritDoc} 572 * @throws NullPointerException {@inheritDoc} 573 */ 574 @Override 575 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { 576 Objects.requireNonNull(annotationClass); 577 578 return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); 579 } 580 581 /** 582 * {@inheritDoc} 583 */ 584 public Annotation[] getDeclaredAnnotations() { 585 return AnnotationParser.toArray(declaredAnnotations()); 586 } 587 588 private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations; 589 590 private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { 591 Map<Class<? extends Annotation>, Annotation> declAnnos; 592 if ((declAnnos = declaredAnnotations) == null) { 593 synchronized (this) { 594 if ((declAnnos = declaredAnnotations) == null) { 595 Executable root = getRoot(); 596 if (root != null) { 597 declAnnos = root.declaredAnnotations(); 598 } else { 599 declAnnos = AnnotationParser.parseAnnotations( 600 getAnnotationBytes(), 601 SharedSecrets.getJavaLangAccess(). 602 getConstantPool(getDeclaringClass()), 603 getDeclaringClass() 604 ); 605 } 606 declaredAnnotations = declAnnos; 607 } 608 } 609 } 610 return declAnnos; 611 } 612 613 /** 614 * Returns an {@code AnnotatedType} object that represents the use of a type to 615 * specify the return type of the method/constructor represented by this 616 * Executable. 617 * 618 * If this {@code Executable} object represents a constructor, the {@code 619 * AnnotatedType} object represents the type of the constructed object. 620 * 621 * If this {@code Executable} object represents a method, the {@code 622 * AnnotatedType} object represents the use of a type to specify the return 623 * type of the method. 624 * 625 * @return an object representing the return type of the method 626 * or constructor represented by this {@code Executable} 627 */ 628 public abstract AnnotatedType getAnnotatedReturnType(); 629 630 /* Helper for subclasses of Executable. 631 * 632 * Returns an AnnotatedType object that represents the use of a type to 633 * specify the return type of the method/constructor represented by this 634 * Executable. 635 */ 636 AnnotatedType getAnnotatedReturnType0(Type returnType) { 637 return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(), 638 SharedSecrets.getJavaLangAccess(). 639 getConstantPool(getDeclaringClass()), 640 this, 641 getDeclaringClass(), 642 returnType, 643 TypeAnnotation.TypeAnnotationTarget.METHOD_RETURN); 644 } 645 646 /** 647 * Returns an {@code AnnotatedType} object that represents the use of a 648 * type to specify the receiver type of the method/constructor represented 649 * by this {@code Executable} object. 650 * 651 * The receiver type of a method/constructor is available only if the 652 * method/constructor has a receiver parameter (JLS 8.4.1). If this {@code 653 * Executable} object <em>represents an instance method or represents a 654 * constructor of an inner member class</em>, and the 655 * method/constructor <em>either</em> has no receiver parameter or has a 656 * receiver parameter with no annotations on its type, then the return 657 * value is an {@code AnnotatedType} object representing an element with no 658 * annotations. 659 * 660 * If this {@code Executable} object represents a static method or 661 * represents a constructor of a top level, static member, local, or 662 * anonymous class, then the return value is null. 663 * 664 * @return an object representing the receiver type of the method or 665 * constructor represented by this {@code Executable} or {@code null} if 666 * this {@code Executable} can not have a receiver parameter 667 */ 668 public AnnotatedType getAnnotatedReceiverType() { 669 if (Modifier.isStatic(this.getModifiers())) 670 return null; 671 return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(), 672 SharedSecrets.getJavaLangAccess(). 673 getConstantPool(getDeclaringClass()), 674 this, 675 getDeclaringClass(), 676 getDeclaringClass(), 677 TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER); 678 } 679 680 /** 681 * Returns an array of {@code AnnotatedType} objects that represent the use 682 * of types to specify formal parameter types of the method/constructor 683 * represented by this Executable. The order of the objects in the array 684 * corresponds to the order of the formal parameter types in the 685 * declaration of the method/constructor. 686 * 687 * Returns an array of length 0 if the method/constructor declares no 688 * parameters. 689 * 690 * @return an array of objects representing the types of the 691 * formal parameters of the method or constructor represented by this 692 * {@code Executable} 693 */ 694 public AnnotatedType[] getAnnotatedParameterTypes() { 695 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(), 696 SharedSecrets.getJavaLangAccess(). 697 getConstantPool(getDeclaringClass()), 698 this, 699 getDeclaringClass(), 700 getAllGenericParameterTypes(), 701 TypeAnnotation.TypeAnnotationTarget.METHOD_FORMAL_PARAMETER); 702 } 703 704 /** 705 * Returns an array of {@code AnnotatedType} objects that represent the use 706 * of types to specify the declared exceptions of the method/constructor 707 * represented by this Executable. The order of the objects in the array 708 * corresponds to the order of the exception types in the declaration of 709 * the method/constructor. 710 * 711 * Returns an array of length 0 if the method/constructor declares no 712 * exceptions. 713 * 714 * @return an array of objects representing the declared 715 * exceptions of the method or constructor represented by this {@code 716 * Executable} 717 */ 718 public AnnotatedType[] getAnnotatedExceptionTypes() { 719 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(), 720 SharedSecrets.getJavaLangAccess(). 721 getConstantPool(getDeclaringClass()), 722 this, 723 getDeclaringClass(), 724 getGenericExceptionTypes(), 725 TypeAnnotation.TypeAnnotationTarget.THROWS); 726 } 727 728 }