8014709: Constructor.getAnnotatedReturnType() returns empty AnnotatedType
authorrbackman
Fri, 31 May 2013 13:02:24 +0200
changeset 17860 1ad3f2d9b4eb
parent 17859 cda7f55ca4dc
child 17861 8f14da01157d
8014709: Constructor.getAnnotatedReturnType() returns empty AnnotatedType Reviewed-by: stefank, rbackman Contributed-by: Joel Borggren-Franck <joel.franck@oracle.com>
hotspot/src/share/vm/runtime/reflection.cpp
hotspot/test/runtime/8007320/ConstMethodTest.java
--- a/hotspot/src/share/vm/runtime/reflection.cpp	Thu May 30 11:46:39 2013 -0700
+++ b/hotspot/src/share/vm/runtime/reflection.cpp	Fri May 31 13:02:24 2013 +0200
@@ -817,6 +817,10 @@
     typeArrayOop an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL);
     java_lang_reflect_Constructor::set_parameter_annotations(ch(), an_oop);
   }
+  if (java_lang_reflect_Constructor::has_type_annotations_field()) {
+    typeArrayOop an_oop = Annotations::make_java_array(method->type_annotations(), CHECK_NULL);
+    java_lang_reflect_Constructor::set_type_annotations(ch(), an_oop);
+  }
   return ch();
 }
 
--- a/hotspot/test/runtime/8007320/ConstMethodTest.java	Thu May 30 11:46:39 2013 -0700
+++ b/hotspot/test/runtime/8007320/ConstMethodTest.java	Fri May 31 13:02:24 2013 +0200
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8007320
+ * @bug 8007320 8014709
  * @summary Test all optional fields in ConstMethod
  * @compile -g -parameters ConstMethodTest.java
  * @run main ConstMethodTest
@@ -74,6 +74,11 @@
 
 @MyAnnotation(name="someName", value = "Hello World")
 public class ConstMethodTest {
+    public @TypeAnno("constructor") ConstMethodTest() { }
+
+    public ConstMethodTest(int i) {
+        // needs a second unannotated constructor
+    }
 
     private static void check(boolean b) {
         if (!b)
@@ -139,10 +144,26 @@
         }
     }
 
+    private static void testConstructor() throws Exception {
+        for (Constructor c : ConstMethodTest.class.getDeclaredConstructors()) {
+            Annotation[] aa = c.getAnnotatedReturnType().getAnnotations();
+            if (c.getParameterTypes().length == 1) { // should be un-annotated
+                check(aa.length == 0);
+            } else if (c.getParameterTypes().length == 0) { //should be annotated
+                check(aa.length == 1);
+                check(((TypeAnno)aa[0]).value().equals("constructor"));
+            } else {
+                //should not happen
+                check(false);
+            }
+        }
+    }
+
     public static void main(java.lang.String[] unused) throws Throwable {
         // pass 5 so kitchenSinkFunc is instantiated with an int
         kitchenSinkFunc("parameter", "param2", 5);
         test1();
+        testConstructor();
     }
 };