6554097: "final" confuses @SuppressWarnings
Reviewed-by: mcimadamore
This commit is contained in:
parent
ec50779b72
commit
a184b53cec
@ -961,22 +961,12 @@ public abstract class Symbol implements Element {
|
||||
}
|
||||
|
||||
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 @@ public abstract class Symbol implements Element {
|
||||
try {
|
||||
data = eval.call();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new AssertionError(ex);
|
||||
}
|
||||
}
|
||||
|
@ -581,6 +581,41 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -637,7 +637,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
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)) {
|
||||
|
26
langtools/test/tools/javac/T6554097.java
Normal file
26
langtools/test/tools/javac/T6554097.java
Normal file
@ -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() {} };
|
||||
}
|
||||
}
|
||||
|
7
langtools/test/tools/javac/T6554097.out
Normal file
7
langtools/test/tools/javac/T6554097.out
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user