8026791: wrong type_path encoded for method_return on an inner class constructor
authorjjg
Sun, 20 Oct 2013 12:46:12 -0700
changeset 21481 f0aeb1da97bd
parent 21480 9d08c2d0fafd
child 21482 21e66f272f98
8026791: wrong type_path encoded for method_return on an inner class constructor Reviewed-by: jjg Contributed-by: wdietl@gmail.com
langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java
--- a/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Sun Oct 20 12:01:43 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Sun Oct 20 12:46:12 2013 -0700
@@ -323,7 +323,16 @@
             if (type == null) {
                 // When type is null, put the type annotations to the symbol.
                 // This is used for constructor return annotations, for which
-                // no appropriate type exists.
+                // we use the type of the enclosing class.
+                type = sym.getEnclosingElement().asType();
+
+                // Declaration annotations are always allowed on constructor returns.
+                // Therefore, use typeAnnotations instead of onlyTypeAnnos.
+                type = typeWithAnnotations(typetree, type, typeAnnotations, typeAnnotations);
+                // Note that we don't use the result, the call to
+                // typeWithAnnotations side-effects the type annotation positions.
+                // This is important for constructors of nested classes.
+
                 sym.appendUniqueTypeAttributes(typeAnnotations);
                 return;
             }
--- a/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java	Sun Oct 20 12:01:43 2013 -0700
+++ b/langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java	Sun Oct 20 12:46:12 2013 -0700
@@ -21,14 +21,16 @@
  * questions.
  */
 
-import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
-
 /*
  * @test
+ * @bug 8026791
  * @summary Test population of reference info for constructor results
  * @compile -g Driver.java ReferenceInfoUtil.java Constructors.java
  * @run main Driver Constructors
  */
+
+import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
+
 public class Constructors {
 
     @TADescriptions({
@@ -42,8 +44,8 @@
     }
 
     @TADescriptions({
-        @TADescription(annotation = "TA", type = METHOD_RETURN),
-        @TADescription(annotation = "TB", type = METHOD_RETURN),
+        @TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {1, 0}),
+        @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}),
         @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
     })
     @TestClass("Test$Inner")
@@ -56,9 +58,9 @@
 
     @TADescriptions({
         @TADescription(annotation = "TA", type = METHOD_RECEIVER),
-        @TADescription(annotation = "TB", type = METHOD_RETURN),
+        @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}),
         @TADescription(annotation = "TC", type = METHOD_RECEIVER),
-        @TADescription(annotation = "TD", type = METHOD_RETURN),
+        @TADescription(annotation = "TD", type = METHOD_RETURN, genericLocation = {1, 0}),
         @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
     })
     @TestClass("Test$Inner")
@@ -72,9 +74,9 @@
     @TADescriptions({
         @TADescription(annotation = "TA", type = METHOD_RECEIVER),
         @TADescription(annotation = "TB", type = METHOD_RECEIVER, genericLocation = {1, 0}),
-        @TADescription(annotation = "TC", type = METHOD_RETURN),
+        @TADescription(annotation = "TC", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}),
         @TADescription(annotation = "TD", type = METHOD_RECEIVER, genericLocation = {1, 0}),
-        @TADescription(annotation = "TE", type = METHOD_RETURN),
+        @TADescription(annotation = "TE", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}),
         @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
     })
     @TestClass("Outer$Middle$Inner")