Hello, I've recently was working on the bugfix for https://bugs.openjdk.java.net/browse/JDK-8140633 and as a result i got that small fix. Also I've adopted presented in bugtracker test and done jtreg test.
Here is patch. This is my first contribution try, so im probably missing something. # HG changeset patch # User fdesu # Date 1452597274 -10800 # Tue Jan 12 14:14:34 2016 +0300 # Node ID c7a11642c1a9bb38d558e8b237afce223c586d14 # Parent d09282af3b521f751a4b4d5056134877f4cd1b0e 8140633: Bugfix for Method.getAnnotatedReturnType() diff --git a/src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java b/src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java --- a/src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java +++ b/src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java @@ -90,7 +90,7 @@ public static LocationInfo nestingForType(Type type, LocationInfo addTo) { if (isArray(type)) - return addTo; + return addTo.pushArray(); if (type instanceof Class) { Class<?> clz = (Class)type; if (clz.getEnclosingClass() == null) diff --git a/test/java/lang/reflect/Method/MethodAnnotatedReturnTypeTest.java b/test/java/lang/reflect/Method/MethodAnnotatedReturnTypeTest.java new file mode 100644 --- /dev/null +++ b/test/java/lang/reflect/Method/MethodAnnotatedReturnTypeTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012, 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. + */ + +import java.lang.annotation.*; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Method; +import java.util.List; + +/* + * @test + * @bug 8140633 + * @summary Ensure that Method.getAnnotatedReturnType() not returns empty annotations when + * type is an array + * @author Sergey Ustimenko + */ +public class MethodAnnotatedReturnTypeTest { + + @Target({ ElementType.TYPE_PARAMETER, ElementType.TYPE_USE }) + @Retention(RetentionPolicy.RUNTIME) + public @interface MyAnnotation { + String value(); + } + + public interface ToImplement { + @MyAnnotation("sayHello") String sayHello(); + @MyAnnotation("sayHello1") List<String> sayHello1(); + @MyAnnotation("sayHello2") String[] sayHello2(); + } + + public static void main(String[] args) { + for (Method m : ToImplement.class.getMethods()) { + AnnotatedType returnType = m.getAnnotatedReturnType(); + if(returnType.getAnnotations().length == 0) + throw new RuntimeException("Method.getAnnotatedReturnType() returned an empty array!"); + } + } + +} \ No newline at end of file
# HG changeset patch # User fdesu # Date 1452597274 -10800 # Tue Jan 12 14:14:34 2016 +0300 # Node ID c7a11642c1a9bb38d558e8b237afce223c586d14 # Parent d09282af3b521f751a4b4d5056134877f4cd1b0e 8140633: Bugfix for Method.getAnnotatedReturnType() diff --git a/src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java b/src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java --- a/src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java +++ b/src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java @@ -90,7 +90,7 @@ public static LocationInfo nestingForType(Type type, LocationInfo addTo) { if (isArray(type)) - return addTo; + return addTo.pushArray(); if (type instanceof Class) { Class<?> clz = (Class)type; if (clz.getEnclosingClass() == null) diff --git a/test/java/lang/reflect/Method/MethodAnnotatedReturnTypeTest.java b/test/java/lang/reflect/Method/MethodAnnotatedReturnTypeTest.java new file mode 100644 --- /dev/null +++ b/test/java/lang/reflect/Method/MethodAnnotatedReturnTypeTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012, 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. + */ + +import java.lang.annotation.*; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Method; +import java.util.List; + +/* + * @test + * @bug 8140633 + * @summary Ensure that Method.getAnnotatedReturnType() not returns empty annotations when + * type is an array + * @author Sergey Ustimenko + */ +public class MethodAnnotatedReturnTypeTest { + + @Target({ ElementType.TYPE_PARAMETER, ElementType.TYPE_USE }) + @Retention(RetentionPolicy.RUNTIME) + public @interface MyAnnotation { + String value(); + } + + public interface ToImplement { + @MyAnnotation("sayHello") String sayHello(); + @MyAnnotation("sayHello1") List<String> sayHello1(); + @MyAnnotation("sayHello2") String[] sayHello2(); + } + + public static void main(String[] args) { + for (Method m : ToImplement.class.getMethods()) { + AnnotatedType returnType = m.getAnnotatedReturnType(); + if(returnType.getAnnotations().length == 0) + throw new RuntimeException("Method.getAnnotatedReturnType() returned an empty array!"); + } + } + +} \ No newline at end of file