changeset 840:df371fd16386

6554097: "final" confuses @SuppressWarnings Reviewed-by: mcimadamore
author jjg
date Wed, 26 Jan 2011 11:20:19 -0800
parents 7f8794f9cc14
children 3da26790ccb7
files src/share/classes/com/sun/tools/javac/code/Symbol.java src/share/classes/com/sun/tools/javac/comp/Attr.java src/share/classes/com/sun/tools/javac/comp/MemberEnter.java test/tools/javac/T6554097.java test/tools/javac/T6554097.out
diffstat 5 files changed, 71 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Jan 25 17:02:56 2011 -0800
+++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Jan 26 11:20:19 2011 -0800
@@ -961,22 +961,12 @@
         }
 
         public void setLazyConstValue(final Env<AttrContext> env,
-                                      final Log log,
                                       final Attr attr,
                                       final JCTree.JCExpression initializer)
         {
             setData(new Callable<Object>() {
                 public Object call() {
-                    JavaFileObject source = log.useSource(env.toplevel.sourcefile);
-                    try {
-                        Type itype = attr.attribExpr(initializer, env, type);
-                        if (itype.constValue() != null)
-                            return attr.coerce(itype, type).constValue();
-                        else
-                            return null;
-                    } finally {
-                        log.useSource(source);
-                    }
+                    return attr.attribLazyConstantValue(env, initializer, type);
                 }
             });
         }
@@ -1010,6 +1000,7 @@
                 try {
                     data = eval.call();
                 } catch (Exception ex) {
+                    ex.printStackTrace();
                     throw new AssertionError(ex);
                 }
             }
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jan 25 17:02:56 2011 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Jan 26 11:20:19 2011 -0800
@@ -581,6 +581,41 @@
         }
     }
 
+    /**
+     * Attribute a "lazy constant value".
+     *  @param env         The env for the const value
+     *  @param initializer The initializer for the const value
+     *  @param type        The expected type, or null
+     *  @see VarSymbol#setlazyConstValue
+     */
+    public Object attribLazyConstantValue(Env<AttrContext> env,
+                                      JCTree.JCExpression initializer,
+                                      Type type) {
+
+        // in case no lint value has been set up for this env, scan up
+        // env stack looking for smallest enclosing env for which it is set.
+        Env<AttrContext> lintEnv = env;
+        while (lintEnv.info.lint == null)
+            lintEnv = lintEnv.next;
+
+        // Having found the enclosing lint value, we can initialize the lint value for this class
+        env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.attributes_field, env.info.enclVar.flags());
+
+        Lint prevLint = chk.setLint(env.info.lint);
+        JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile);
+
+        try {
+            Type itype = attribExpr(initializer, env, type);
+            if (itype.constValue() != null)
+                return coerce(itype, type).constValue();
+            else
+                return null;
+        } finally {
+            env.info.lint = prevLint;
+            log.useSource(prevSource);
+        }
+    }
+
     /** Attribute type reference in an `extends' or `implements' clause.
      *  Supertypes of anonymous inner classes are usually already attributed.
      *
--- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue Jan 25 17:02:56 2011 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Wed Jan 26 11:20:19 2011 -0800
@@ -637,7 +637,7 @@
             if ((v.flags_field & FINAL) != 0 && tree.init.getTag() != JCTree.NEWCLASS) {
                 Env<AttrContext> initEnv = getInitEnv(tree, env);
                 initEnv.info.enclVar = v;
-                v.setLazyConstValue(initEnv(tree, initEnv), log, attr, tree.init);
+                v.setLazyConstValue(initEnv(tree, initEnv), attr, tree.init);
             }
         }
         if (chk.checkUnique(tree.pos(), v, enclScope)) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/T6554097.java	Wed Jan 26 11:20:19 2011 -0800
@@ -0,0 +1,26 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug     6554097
+ * @summary "final" confuses at-SuppressWarnings
+ * @compile T6554097.java
+ * @compile/fail/ref=T6554097.out -XDrawDiagnostics -Werror -Xlint:serial T6554097.java
+ */
+
+class T6554097 {
+    @SuppressWarnings("serial") final Throwable[] v1 = { new Throwable() {} };
+    @SuppressWarnings("serial")       Throwable[] v2 = { new Throwable() {} };
+
+    public static void m1() throws Throwable {
+            @SuppressWarnings("serial") final Throwable[] v3 = { new Throwable() {} };
+            @SuppressWarnings("serial")       Throwable[] v4 = { new Throwable() {} };
+    }
+
+    final Throwable[] v5 = { new Throwable() {} };
+          Throwable[] v6 = { new Throwable() {} };
+
+    public static void m2() throws Throwable {
+        final Throwable[] v7 = { new Throwable() {} };
+                  Throwable[] v8 = { new Throwable() {} };
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/T6554097.out	Wed Jan 26 11:20:19 2011 -0800
@@ -0,0 +1,7 @@
+T6554097.java:18:46: compiler.warn.missing.SVUID: compiler.misc.anonymous.class: T6554097$5
+T6554097.java:19:46: compiler.warn.missing.SVUID: compiler.misc.anonymous.class: T6554097$6
+T6554097.java:22:50: compiler.warn.missing.SVUID: compiler.misc.anonymous.class: T6554097$7
+T6554097.java:23:54: compiler.warn.missing.SVUID: compiler.misc.anonymous.class: T6554097$8
+- compiler.err.warnings.and.werror
+1 error
+4 warnings