Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8073056

Repeating annotations throws java.security.AccessControlException with a SecurityManager

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 8, 9
    • core-libs

        public class TestAnnotations {

           @MyAnnotation(name = "foo")
           private static class OneAnnotation {
           }

           @MyAnnotation(name = "foo")
           @MyAnnotation(name = "bar")
           private static class TwoAnnotations {
           }

           public static void main(String argv[]) throws Exception {
               annotationCount(OneAnnotation.class);
               annotationCount(TwoAnnotations.class);

               //load empty security policy
               loadSecurityPolicy();

               annotationCount(OneAnnotation.class);
               annotationCount(TwoAnnotations.class);
           }

           private static void annotationCount(Class<?> clazz) {
               MyAnnotation[] annotations = clazz.getAnnotationsByType(MyAnnotation.class);
               System.err.println(clazz.getSimpleName() + " annotation count: " + annotations.length);
           }
           ...
        }

        OneAnnotation annotation count: 1
        TwoAnnotations annotation count: 2
        OneAnnotation annotation count: 1
        Exception in thread "main" java.security.AccessControlException: access denied ("java.lang.reflect.ReflectPermission" "suppressAccessChecks")
           at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
           at java.security.AccessController.checkPermission(AccessController.java:884)
           at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
           at java.lang.reflect.AccessibleObject.setAccessible(AccessibleObject.java:128)
           at sun.reflect.annotation.AnnotationSupport.getValueArray(AnnotationSupport.java:196)
           at sun.reflect.annotation.AnnotationSupport.getIndirectlyPresent(AnnotationSupport.java:110)
           at

              jfranck Joel Borggrén-Franck (Inactive)
              jfranck Joel Borggrén-Franck (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: