Skip to content

Commit d0502e8

Browse files
authored
Fix issue with annotations in module-info.java files (#1109)
1 parent f17b330 commit d0502e8

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/ModuleInfoTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public void testModuleInfo() {
3535
defaultCompilationHelper
3636
.addSourceLines(
3737
"module-info.java",
38+
"@SuppressWarnings(\"some-warning-name\")",
3839
"module com.uber.mymodule {",
3940
" // Important: two-level deep module tests matching of identifier `java` as base expression;",
4041
" // see further discussion at https://github.com/uber/NullAway/pull/544#discussion_r780829467",

nullaway/src/main/java/com/uber/nullaway/NullAway.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,12 @@ public Description matchAssignment(AssignmentTree tree, VisitorState state) {
486486
doUnboxingCheck(state, tree.getExpression());
487487
}
488488
Symbol assigned = ASTHelpers.getSymbol(tree.getVariable());
489+
if (assigned instanceof Symbol.MethodSymbol) {
490+
// javac generates an AssignmentTree for setting an annotation attribute value. E.g., for
491+
// `@SuppressWarnings("foo")`, javac generates an AssignmentTree of the form `value() =
492+
// "foo"`, where the LHS is a MethodSymbol. We don't want to analyze these.
493+
return Description.NO_MATCH;
494+
}
489495
if (assigned != null && codeAnnotationInfo.isSymbolUnannotated(assigned, config, handler)) {
490496
// assigning to symbol that is unannotated
491497
return Description.NO_MATCH;

0 commit comments

Comments
 (0)