Path: blob/master/test/jdk/java/lang/annotation/repeatingAnnotations/RepeatingWithSecurityManager.java
41153 views
/*1* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 807305626* @summary Repeating annotations throws java.security.AccessControlException with a SecurityManager27*28* @library /test/lib29* @build jdk.test.lib.Asserts30* @run main RepeatingWithSecurityManager31* @run main/othervm -Djava.security.manager=allow RepeatingWithSecurityManager "withSM"32*/3334import java.lang.annotation.*;35import java.util.*;3637import jdk.test.lib.Asserts;3839public class RepeatingWithSecurityManager {40public static void main(String[] args) throws Exception {41if (args.length == 1) {42SecurityManager sm = new SecurityManager();43System.setSecurityManager(sm);44}4546Asserts.assertTrue(TwoAnnotations.class.getAnnotationsByType(MyAnnotation.class).length == 2,47"Array should contain 2 annotations: " +48Arrays.toString(TwoAnnotations.class.getAnnotationsByType(MyAnnotation.class)));49}5051@MyAnnotation(name = "foo")52@MyAnnotation(name = "bar")53private static class TwoAnnotations {54}5556@Retention(RetentionPolicy.RUNTIME)57@interface MyAnnotations {58MyAnnotation[] value();59}6061@Retention(RetentionPolicy.RUNTIME)62@Repeatable(MyAnnotations.class)63@interface MyAnnotation {64String name();65}66}676869