0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 6332964
0N/A * @summary Verify getParameterAnnotations doesn't throw spurious errors
0N/A * @author Joseph D. Darcy
0N/A */
0N/A
0N/Aimport java.lang.reflect.*;
0N/Aimport java.lang.annotation.*;
0N/Aimport static java.lang.annotation.RetentionPolicy.*;
0N/Aimport java.util.Arrays;
0N/A
0N/Apublic class TestParameterAnnotations {
0N/A class Inner {
0N/A public Inner(@Marker Object o) {}
0N/A }
0N/A
0N/A static class StaticNested {
0N/A public StaticNested(@Marker Object o) {}
0N/A }
0N/A
0N/A static int visitCtorParameterAnnotations(Class clazz) {
0N/A int errors = 0;
0N/A for(Constructor<?> ctor : clazz.getDeclaredConstructors()) {
0N/A try {
0N/A System.out.printf("%nNormal: %s%nGeneric: %s%n",
0N/A ctor.toString(),
0N/A ctor.toGenericString());
0N/A Annotation[][] annotationArray = ctor.getParameterAnnotations();
0N/A System.out.println("\tParameter Annotations: " +
0N/A Arrays.deepToString(annotationArray));
0N/A } catch (AnnotationFormatError afe) {
0N/A System.err.println("\tWhoops, got an AnnotationFormatError on " +
0N/A ctor.toGenericString());
0N/A errors++;
0N/A }
0N/A }
0N/A return errors;
0N/A }
0N/A
0N/A public static void main(String... argv) {
0N/A int errors = 0;
0N/A class LocalClass {
0N/A LocalClass(@Marker int i){}
0N/A }
0N/A
0N/A Object anonymous = new Object() {public String toString(){return "Anonymous";}};
0N/A
0N/A errors +=
0N/A visitCtorParameterAnnotations(Inner.class);
0N/A errors +=
0N/A visitCtorParameterAnnotations(StaticNested.class);
0N/A errors +=
0N/A visitCtorParameterAnnotations(CustomColors.class);
0N/A errors +=
0N/A visitCtorParameterAnnotations(TestParameterAnnotations.class);
0N/A errors +=
0N/A visitCtorParameterAnnotations(LocalClass.class);
0N/A errors +=
0N/A visitCtorParameterAnnotations(anonymous.getClass());
0N/A
0N/A if (errors > 0)
0N/A throw new RuntimeException(errors +
0N/A " failures calling Constructor.getParameterAnnotations");
0N/A }
0N/A}
0N/A
0N/Aenum CustomColors {
0N/A FUCHSIA(5),
0N/A MULBERRY(6.0d);
0N/A CustomColors(@Marker int arg) {}
0N/A CustomColors(double arg) {}
0N/A}
0N/A
0N/A@Retention(RUNTIME)
0N/A @interface Marker {}