Skip to content

Commit

Permalink
Fix issue with annotations in module-info.java files (#1109)
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar authored Dec 22, 2024
1 parent f17b330 commit d0502e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void testModuleInfo() {
defaultCompilationHelper
.addSourceLines(
"module-info.java",
"@SuppressWarnings(\"some-warning-name\")",
"module com.uber.mymodule {",
" // Important: two-level deep module tests matching of identifier `java` as base expression;",
" // see further discussion at https://github.com/uber/NullAway/pull/544#discussion_r780829467",
Expand Down
6 changes: 6 additions & 0 deletions nullaway/src/main/java/com/uber/nullaway/NullAway.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ public Description matchAssignment(AssignmentTree tree, VisitorState state) {
doUnboxingCheck(state, tree.getExpression());
}
Symbol assigned = ASTHelpers.getSymbol(tree.getVariable());
if (assigned instanceof Symbol.MethodSymbol) {
// javac generates an AssignmentTree for setting an annotation attribute value. E.g., for
// `@SuppressWarnings("foo")`, javac generates an AssignmentTree of the form `value() =
// "foo"`, where the LHS is a MethodSymbol. We don't want to analyze these.
return Description.NO_MATCH;
}
if (assigned != null && codeAnnotationInfo.isSymbolUnannotated(assigned, config, handler)) {
// assigning to symbol that is unannotated
return Description.NO_MATCH;
Expand Down

0 comments on commit d0502e8

Please sign in to comment.