Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with annotations in module-info.java files #1109

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading