Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/reflect/Constructor/TestParameterAnnotations.java
38828 views
/*1* Copyright (c) 2005, 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 633296426* @summary Verify getParameterAnnotations doesn't throw spurious errors27* @author Joseph D. Darcy28*/2930import java.lang.reflect.*;31import java.lang.annotation.*;32import static java.lang.annotation.RetentionPolicy.*;33import java.util.Arrays;3435public class TestParameterAnnotations {36class Inner {37public Inner(@Marker Object o) {}38}3940static class StaticNested {41public StaticNested(@Marker Object o) {}42}4344static int visitCtorParameterAnnotations(Class clazz) {45int errors = 0;46for(Constructor<?> ctor : clazz.getDeclaredConstructors()) {47try {48System.out.printf("%nNormal: %s%nGeneric: %s%n",49ctor.toString(),50ctor.toGenericString());51Annotation[][] annotationArray = ctor.getParameterAnnotations();52System.out.println("\tParameter Annotations: " +53Arrays.deepToString(annotationArray));54} catch (AnnotationFormatError afe) {55System.err.println("\tWhoops, got an AnnotationFormatError on " +56ctor.toGenericString());57errors++;58}59}60return errors;61}6263public static void main(String... argv) {64int errors = 0;65class LocalClass {66LocalClass(@Marker int i){}67}6869Object anonymous = new Object() {public String toString(){return "Anonymous";}};7071errors +=72visitCtorParameterAnnotations(Inner.class);73errors +=74visitCtorParameterAnnotations(StaticNested.class);75errors +=76visitCtorParameterAnnotations(CustomColors.class);77errors +=78visitCtorParameterAnnotations(TestParameterAnnotations.class);79errors +=80visitCtorParameterAnnotations(LocalClass.class);81errors +=82visitCtorParameterAnnotations(anonymous.getClass());8384if (errors > 0)85throw new RuntimeException(errors +86" failures calling Constructor.getParameterAnnotations");87}88}8990enum CustomColors {91FUCHSIA(5),92MULBERRY(6.0d);93CustomColors(@Marker int arg) {}94CustomColors(double arg) {}95}9697@Retention(RUNTIME)98@interface Marker {}99100101