549
550 /**
551 * @throws NullPointerException {@inheritDoc}
552 * @since 1.8
553 */
554 @Override
555 public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
556 // Only annotations on classes are inherited, for all other
557 // objects getDeclaredAnnotationsByType is the same as
558 // getAnnotationsByType.
559 return getAnnotationsByType(annotationClass);
560 }
561
562 /**
563 * @since 1.5
564 */
565 public Annotation[] getDeclaredAnnotations() {
566 throw new AssertionError("All subclasses should override this method");
567 }
568
569
570 // Shared access checking logic.
571
572 // For non-public members or members in package-private classes,
573 // it is necessary to perform somewhat expensive security checks.
574 // If the security check succeeds for a given class, it will
575 // always succeed (it is not affected by the granting or revoking
576 // of permissions); we speed up the check in the common case by
577 // remembering the last Class for which the check succeeded.
578 //
579 // The simple security check for Constructor is to see if
580 // the caller has already been seen, verified, and cached.
581 // (See also Class.newInstance(), which uses a similar method.)
582 //
583 // A more complicated security check cache is needed for Method and Field
584 // The cache can be either null (empty cache), a 2-array of {caller,targetClass},
585 // or a caller (with targetClass implicitly equal to memberClass).
586 // In the 2-array case, the targetClass is always different from the memberClass.
587 volatile Object securityCheckCache;
588
589 final void checkAccess(Class<?> caller, Class<?> memberClass,
659 // true to print a stack trace when access fails
660 private static volatile boolean printStackWhenAccessFails;
661
662 // true if printStack* values are initialized
663 private static volatile boolean printStackPropertiesSet;
664
665 /**
666 * Returns true if a stack trace should be printed when access fails.
667 */
668 private static boolean printStackTraceWhenAccessFails() {
669 if (!printStackPropertiesSet && VM.initLevel() >= 1) {
670 String s = GetPropertyAction.privilegedGetProperty(
671 "sun.reflect.debugModuleAccessChecks");
672 if (s != null) {
673 printStackWhenAccessFails = !s.equalsIgnoreCase("false");
674 }
675 printStackPropertiesSet = true;
676 }
677 return printStackWhenAccessFails;
678 }
679 }
|
549
550 /**
551 * @throws NullPointerException {@inheritDoc}
552 * @since 1.8
553 */
554 @Override
555 public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
556 // Only annotations on classes are inherited, for all other
557 // objects getDeclaredAnnotationsByType is the same as
558 // getAnnotationsByType.
559 return getAnnotationsByType(annotationClass);
560 }
561
562 /**
563 * @since 1.5
564 */
565 public Annotation[] getDeclaredAnnotations() {
566 throw new AssertionError("All subclasses should override this method");
567 }
568
569 // Shared access checking logic.
570
571 // For non-public members or members in package-private classes,
572 // it is necessary to perform somewhat expensive security checks.
573 // If the security check succeeds for a given class, it will
574 // always succeed (it is not affected by the granting or revoking
575 // of permissions); we speed up the check in the common case by
576 // remembering the last Class for which the check succeeded.
577 //
578 // The simple security check for Constructor is to see if
579 // the caller has already been seen, verified, and cached.
580 // (See also Class.newInstance(), which uses a similar method.)
581 //
582 // A more complicated security check cache is needed for Method and Field
583 // The cache can be either null (empty cache), a 2-array of {caller,targetClass},
584 // or a caller (with targetClass implicitly equal to memberClass).
585 // In the 2-array case, the targetClass is always different from the memberClass.
586 volatile Object securityCheckCache;
587
588 final void checkAccess(Class<?> caller, Class<?> memberClass,
658 // true to print a stack trace when access fails
659 private static volatile boolean printStackWhenAccessFails;
660
661 // true if printStack* values are initialized
662 private static volatile boolean printStackPropertiesSet;
663
664 /**
665 * Returns true if a stack trace should be printed when access fails.
666 */
667 private static boolean printStackTraceWhenAccessFails() {
668 if (!printStackPropertiesSet && VM.initLevel() >= 1) {
669 String s = GetPropertyAction.privilegedGetProperty(
670 "sun.reflect.debugModuleAccessChecks");
671 if (s != null) {
672 printStackWhenAccessFails = !s.equalsIgnoreCase("false");
673 }
674 printStackPropertiesSet = true;
675 }
676 return printStackWhenAccessFails;
677 }
678
679 /**
680 * Returns the root AccessibleObject; or null if this object is the root.
681 *
682 * All subclasses override this method.
683 */
684 AccessibleObject getRoot() {
685 throw new InternalError();
686 }
687 }
|