changeset 2565:ae4f5cb78ebd

8026791: wrong type_path encoded for method_return on an inner class constructor Reviewed-by: jjg Contributed-by: wdietl@gmail.com
author jjg
date Sun, 20 Oct 2013 12:46:12 -0700
parents e5d3cd43c85e
children 399c738e5103
files src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java
diffstat 2 files changed, 20 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Sun Oct 20 12:01:43 2013 -0700
+++ b/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/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java	Sun Oct 20 12:01:43 2013 -0700
+++ b/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")