Skip to content

Commit

Permalink
Merge branch 'master' into issue-1088
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar authored Dec 12, 2024
2 parents a2eef51 + 1fc39b3 commit 73c536d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
7 changes: 1 addition & 6 deletions nullaway/src/main/java/com/uber/nullaway/NullAway.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,8 @@ public Description matchAssignment(AssignmentTree tree, VisitorState state) {
String message = "Writing @Nullable expression into array with @NonNull contents.";
ErrorMessage errorMessage =
new ErrorMessage(MessageTypes.ASSIGN_NULLABLE_TO_NONNULL_ARRAY, message);
// Future enhancements which auto-fix such warnings will require modification to this
// logic
return errorBuilder.createErrorDescription(
errorMessage,
buildDescription(tree),
state,
ASTHelpers.getSymbol(tree.getVariable()));
errorMessage, buildDescription(tree), state, arraySymbol);
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions nullaway/src/test/java/com/uber/nullaway/SerializationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2126,4 +2126,46 @@ public void anonymousSubClassConstructorSerializationTest() {
.setOutputFileNameAndHeader(ERROR_FILE_NAME, ERROR_FILE_HEADER)
.doTest();
}

@Test
public void errorSerializationTestArrayComponentNull() {
SerializationTestHelper<ErrorDisplay> tester = new SerializationTestHelper<>(root);
tester
.setArgs(
Arrays.asList(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-XepOpt:NullAway:SerializeFixMetadata=true",
"-XepOpt:NullAway:JSpecifyMode=true",
"-XepOpt:NullAway:FixSerializationConfigPath=" + configPath))
.addSourceLines(
"com/uber/A.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"public class A {",
" String [] foo = {\"SomeRandomWords\"};",
" void spin() {",
" // BUG: Diagnostic contains: Writing @Nullable expression into array with @NonNull contents.",
" foo[1] = null;",
" }",
"}")
.setExpectedOutputs(
new ErrorDisplay(
"ASSIGN_NULLABLE_TO_NONNULL_ARRAY",
"Writing @Nullable expression into array with @NonNull contents.",
"com.uber.A",
"spin()",
233,
"com/uber/A.java",
"FIELD",
"com.uber.A",
"null",
"foo",
"null",
"com/uber/A.java"))
.setFactory(errorDisplayFactory)
.setOutputFileNameAndHeader(ERROR_FILE_NAME, ERROR_FILE_HEADER)
.doTest();
}
}

0 comments on commit 73c536d

Please sign in to comment.