mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 19:14:38 +02:00
8016099: Some @SuppressWarnings annotations ignored ( unchecked, rawtypes )
Reviewed-by: jjg
This commit is contained in:
parent
9e35962ebf
commit
4e49cb5fc5
4 changed files with 56 additions and 20 deletions
|
@ -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;
|
||||
/* 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();
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue