From e92da66e0bb1c49f306b9d644f23b7e16a20f342 Mon Sep 17 00:00:00 2001 From: Eric McCorkle Date: Tue, 1 Oct 2013 17:35:32 -0400 Subject: [PATCH] 8021398: j.l.r.Parameter.getAnnotatedType().getType() for not annotated use of type returns null Fixed issue with type annotation reflection framework that would cause getType of AnnotatedTypes to be null if no annotations were present. Reviewed-by: darcy, jfranck --- .../annotation/TypeAnnotationParser.java | 16 +++++--- .../Parameter/GetAnnotatedTypeTest.java | 39 +++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 jdk/test/java/lang/reflect/Parameter/GetAnnotatedTypeTest.java diff --git a/jdk/src/share/classes/sun/reflect/annotation/TypeAnnotationParser.java b/jdk/src/share/classes/sun/reflect/annotation/TypeAnnotationParser.java index 12fa1fa687b..bcf48ffe632 100644 --- a/jdk/src/share/classes/sun/reflect/annotation/TypeAnnotationParser.java +++ b/jdk/src/share/classes/sun/reflect/annotation/TypeAnnotationParser.java @@ -128,14 +128,18 @@ public class TypeAnnotationParser { for (int i = 0; i < size; i++) { @SuppressWarnings("unchecked") ArrayList list = l[i]; + TypeAnnotation[] typeAnnotations; if (list != null) { - TypeAnnotation[] typeAnnotations = list.toArray(new TypeAnnotation[0]); - result[i] = AnnotatedTypeFactory.buildAnnotatedType(types[i], - LocationInfo.BASE_LOCATION, - typeAnnotations, - typeAnnotations, - decl); + typeAnnotations = list.toArray(new TypeAnnotation[list.size()]); + } else { + typeAnnotations = EMPTY_TYPE_ANNOTATION_ARRAY; } + result[i] = AnnotatedTypeFactory.buildAnnotatedType(types[i], + LocationInfo.BASE_LOCATION, + typeAnnotations, + typeAnnotations, + decl); + } return result; } diff --git a/jdk/test/java/lang/reflect/Parameter/GetAnnotatedTypeTest.java b/jdk/test/java/lang/reflect/Parameter/GetAnnotatedTypeTest.java new file mode 100644 index 00000000000..2fcf0b8926e --- /dev/null +++ b/jdk/test/java/lang/reflect/Parameter/GetAnnotatedTypeTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @compile -parameters GetAnnotatedTypeTest.java + * @run main GetAnnotatedTypeTest + * @summary javac should generate method parameters correctly. + */ + +public class GetAnnotatedTypeTest { + + public void meth(Object param) {} + + public static void main(String[] args) throws NoSuchMethodException { + if (GetAnnotatedTypeTest.class.getMethod("meth", Object.class).getParameters()[0].getAnnotatedType().getType() != Object.class) + throw new RuntimeException("Parameter did not have the expected annotated type"); + } +}