6554097: "final" confuses @SuppressWarnings
authorjjg
Wed, 26 Jan 2011 11:20:19 -0800
changeset 8225 e9e5670e6a71
parent 8224 8f18e1622660
child 8226 8c2fd7e7bcf3
6554097: "final" confuses @SuppressWarnings Reviewed-by: mcimadamore
langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
langtools/test/tools/javac/T6554097.java
langtools/test/tools/javac/T6554097.out
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Jan 25 17:02:56 2011 -0800
+++ b/langtools/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/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jan 25 17:02:56 2011 -0800
+++ b/langtools/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/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue Jan 25 17:02:56 2011 -0800
+++ b/langtools/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/langtools/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/langtools/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