# HG changeset patch # User jjg # Date 1382298372 25200 # Node ID ae4f5cb78ebd632e5d1855dd951a84f349d6df2c # Parent e5d3cd43c85e8781e891e2a0835650697d27a448 8026791: wrong type_path encoded for method_return on an inner class constructor Reviewed-by: jjg Contributed-by: wdietl@gmail.com diff -r e5d3cd43c85e -r ae4f5cb78ebd src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java --- 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; } diff -r e5d3cd43c85e -r ae4f5cb78ebd test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java --- 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")