提交 5cb4d34f 编写于 作者: V vromero

8016099: Some @SuppressWarnings annotations ignored ( unchecked, rawtypes )

Reviewed-by: jjg
上级 a906d5f6
......@@ -756,25 +756,15 @@ public class Attr extends JCTree.Visitor {
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
// ... but ...
// There's a problem with evaluating annotations in the right order, such that
// env.info.enclVar.attributes_field might not yet have been evaluated, and so might be
// null. In that case, calling augment will throw an NPE. To avoid this, for now we
// revert to the jdk 6 behavior and ignore the (unevaluated) attributes.
if (env.info.enclVar.annotationsPendingCompletion()) {
env.info.lint = lintEnv.info.lint;
} else {
env.info.lint = lintEnv.info.lint.augment(env.info.enclVar);
}
/* When this env was created, it didn't have the correct lint nor had
* annotations has been processed.
* But now at this phase we have already processed annotations and the
* correct lint must have been set in chk, so we should use that one to
* attribute the initializer.
*/
Lint prevLint = env.info.lint;
env.info.lint = chk.getLint();
Lint prevLint = chk.setLint(env.info.lint);
JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile);
try {
......@@ -786,10 +776,11 @@ public class Attr extends JCTree.Visitor {
memberEnter.typeAnnotate(initializer, env, null);
annotate.flush();
Type itype = attribExpr(initializer, env, type);
if (itype.constValue() != null)
if (itype.constValue() != null) {
return coerce(itype, type).constValue();
else
} else {
return null;
}
} finally {
env.info.lint = prevLint;
log.useSource(prevSource);
......
......@@ -218,6 +218,14 @@ public class Check {
return prev;
}
/* This idiom should be used only in cases when it is needed to set the lint
* of an environment that has been created in a phase previous to annotations
* processing.
*/
Lint getLint() {
return lint;
}
DeferredLintHandler setDeferredLintHandler(DeferredLintHandler newDeferredLintHandler) {
DeferredLintHandler prev = deferredLintHandler;
deferredLintHandler = newDeferredLintHandler;
......
/*
* @test /nodynamiccopyright/
* @bug 8016099
* @summary Some SuppressWarnings annotations ignored ( unchecked, rawtypes )
* @compile UncheckedWarningRegressionTest.java
* @compile/fail/ref=UncheckedWarningRegressionTest.out -XDrawDiagnostics -Werror -Xlint:unchecked UncheckedWarningRegressionTest.java
*/
public class UncheckedWarningRegressionTest {
<T> void suppressedWarningsFinalInitializer() {
@SuppressWarnings("unchecked")
T[] tt = (T[]) FINAL_EMPTY_ARRAY;
}
final Object[] FINAL_EMPTY_ARRAY = {};
<T> void finalInitializer() {
T[] tt = (T[]) FINAL_EMPTY_ARRAY;
}
<T> void suppressedWarningsNonFinalInitializer() {
@SuppressWarnings("unchecked")
T[] tt = (T[]) NON_FINAL_EMPTY_ARRAY;
}
Object[] NON_FINAL_EMPTY_ARRAY = {};
<T> void nonFinalInitializer() {
T[] tt = (T[]) NON_FINAL_EMPTY_ARRAY;
}
}
UncheckedWarningRegressionTest.java:18:24: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Object[], T[]
UncheckedWarningRegressionTest.java:29:24: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Object[], T[]
- compiler.err.warnings.and.werror
1 error
2 warnings
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册