changeset 2272:141987ea3421

Ensure that a TypeCompound is only created once per annotation, preventing duplicates appearing for lazy constant values.
author wmdietl
date Mon, 25 Feb 2013 17:12:07 -0800
parents 9ec2520c8016
children 8c7da944ce32
files src/share/classes/com/sun/tools/javac/comp/Annotate.java test/tools/javac/annotations/typeAnnotations/failures/LazyConstantValue.java test/tools/javac/annotations/typeAnnotations/failures/LazyConstantValue.out test/tools/javac/annotations/typeAnnotations/referenceinfos/Initializers.java
diffstat 3 files changed, 22 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Mon Feb 25 17:10:35 2013 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Mon Feb 25 17:12:07 2013 -0800
@@ -356,10 +356,14 @@
     Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a,
             Type expected,
             Env<AttrContext> env) {
-        Attribute.Compound c = enterAnnotation(a, expected, env);
-        Attribute.TypeCompound tc = new Attribute.TypeCompound(c.type, c.values, new TypeAnnotationPosition());
-        a.attribute = tc;
-        return tc;
+        if (a.attribute == null) {
+            Attribute.Compound c = enterAnnotation(a, expected, env);
+            Attribute.TypeCompound tc = new Attribute.TypeCompound(c.type, c.values, new TypeAnnotationPosition());
+            a.attribute = tc;
+            return tc;
+        } else {
+            return (Attribute.TypeCompound) a.attribute;
+        }
     }
 
     /* *********************************
--- a/test/tools/javac/annotations/typeAnnotations/failures/LazyConstantValue.java	Mon Feb 25 17:10:35 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/LazyConstantValue.java	Mon Feb 25 17:12:07 2013 -0800
@@ -27,7 +27,7 @@
  * @summary Type annotations in a lazy constant need to be attributed
  *   in the correct order.
  * @author Werner Dietl
- * @compile LazyConstantValue.java
+ * @compile/ref=LazyConstantValue.out LazyConstantValue.java
  */
 
 import java.lang.annotation.*;
@@ -40,5 +40,9 @@
     static final String[] lcv = new @TA String[0];
 }
 
+class ClassC {
+    static final Object o = (@TA Object) null;
+}
+
 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
 @interface TA {}
--- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/Initializers.java	Mon Feb 25 17:10:35 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Initializers.java	Mon Feb 25 17:12:07 2013 -0800
@@ -83,4 +83,13 @@
 
     // TODO: test interaction with several constructors, especially non-initial constuctors.
     // I don't think this kind of test is possible here.
+
+    @TADescriptions({
+        @TADescription(annotation = "TA", type = CAST,
+                typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE),
+    })
+    public String lazyConstantCast1() {
+        return "class Test { public static final Object o = (@TA Object) null; }";
+    }
+
 }