Sun, 20 Oct 2013 12:46:12 -0700
8026791: wrong type_path encoded for method_return on an inner class constructor
Reviewed-by: jjg
Contributed-by: wdietl@gmail.com
1.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Sun Oct 20 12:01:43 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Sun Oct 20 12:46:12 2013 -0700 1.3 @@ -323,7 +323,16 @@ 1.4 if (type == null) { 1.5 // When type is null, put the type annotations to the symbol. 1.6 // This is used for constructor return annotations, for which 1.7 - // no appropriate type exists. 1.8 + // we use the type of the enclosing class. 1.9 + type = sym.getEnclosingElement().asType(); 1.10 + 1.11 + // Declaration annotations are always allowed on constructor returns. 1.12 + // Therefore, use typeAnnotations instead of onlyTypeAnnos. 1.13 + type = typeWithAnnotations(typetree, type, typeAnnotations, typeAnnotations); 1.14 + // Note that we don't use the result, the call to 1.15 + // typeWithAnnotations side-effects the type annotation positions. 1.16 + // This is important for constructors of nested classes. 1.17 + 1.18 sym.appendUniqueTypeAttributes(typeAnnotations); 1.19 return; 1.20 }
2.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java Sun Oct 20 12:01:43 2013 -0700 2.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java Sun Oct 20 12:46:12 2013 -0700 2.3 @@ -21,14 +21,16 @@ 2.4 * questions. 2.5 */ 2.6 2.7 -import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; 2.8 - 2.9 /* 2.10 * @test 2.11 + * @bug 8026791 2.12 * @summary Test population of reference info for constructor results 2.13 * @compile -g Driver.java ReferenceInfoUtil.java Constructors.java 2.14 * @run main Driver Constructors 2.15 */ 2.16 + 2.17 +import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; 2.18 + 2.19 public class Constructors { 2.20 2.21 @TADescriptions({ 2.22 @@ -42,8 +44,8 @@ 2.23 } 2.24 2.25 @TADescriptions({ 2.26 - @TADescription(annotation = "TA", type = METHOD_RETURN), 2.27 - @TADescription(annotation = "TB", type = METHOD_RETURN), 2.28 + @TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {1, 0}), 2.29 + @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}), 2.30 @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 2.31 }) 2.32 @TestClass("Test$Inner") 2.33 @@ -56,9 +58,9 @@ 2.34 2.35 @TADescriptions({ 2.36 @TADescription(annotation = "TA", type = METHOD_RECEIVER), 2.37 - @TADescription(annotation = "TB", type = METHOD_RETURN), 2.38 + @TADescription(annotation = "TB", type = METHOD_RETURN, genericLocation = {1, 0}), 2.39 @TADescription(annotation = "TC", type = METHOD_RECEIVER), 2.40 - @TADescription(annotation = "TD", type = METHOD_RETURN), 2.41 + @TADescription(annotation = "TD", type = METHOD_RETURN, genericLocation = {1, 0}), 2.42 @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 2.43 }) 2.44 @TestClass("Test$Inner") 2.45 @@ -72,9 +74,9 @@ 2.46 @TADescriptions({ 2.47 @TADescription(annotation = "TA", type = METHOD_RECEIVER), 2.48 @TADescription(annotation = "TB", type = METHOD_RECEIVER, genericLocation = {1, 0}), 2.49 - @TADescription(annotation = "TC", type = METHOD_RETURN), 2.50 + @TADescription(annotation = "TC", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}), 2.51 @TADescription(annotation = "TD", type = METHOD_RECEIVER, genericLocation = {1, 0}), 2.52 - @TADescription(annotation = "TE", type = METHOD_RETURN), 2.53 + @TADescription(annotation = "TE", type = METHOD_RETURN, genericLocation = {1, 0, 1, 0}), 2.54 @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0) 2.55 }) 2.56 @TestClass("Outer$Middle$Inner")