Skip to content

Commit

Permalink
Fix crash with suggested suppressions in JSpecify mode (#1001)
Browse files Browse the repository at this point in the history
We were calling the wrong overload and hence accidentally passing an
incorrect tree on which to apply a `@SuppressWarnings` annotation.

Fixes #996
  • Loading branch information
msridhar authored Jul 22, 2024
1 parent e0718a8 commit 43bbb79
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
1 change: 0 additions & 1 deletion nullaway/src/main/java/com/uber/nullaway/NullAway.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ public Description matchAssignment(AssignmentTree tree, VisitorState state) {
// logic
return errorBuilder.createErrorDescription(
errorMessage,
expression,
buildDescription(tree),
state,
ASTHelpers.getSymbol(tree.getVariable()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.uber.nullaway.jspecify;

import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.uber.nullaway.NullAway;
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/** Tests for combining fix suggestions with JSpecify mode. */
public class SuggestedFixesTests {

@Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();

private BugCheckerRefactoringTestHelper makeTestHelper() {
return BugCheckerRefactoringTestHelper.newInstance(NullAway.class, getClass())
.setArgs(
"-d",
temporaryFolder.getRoot().getAbsolutePath(),
"-processorpath",
SuggestedFixesTests.class.getProtectionDomain().getCodeSource().getLocation().getPath(),
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-XepOpt:NullAway:JSpecifyMode=true",
"-XepOpt:NullAway:SuggestSuppressions=true");
}

@Test
public void suggestSuppressionForAssigningNullableIntoNonNullArray() throws IOException {
makeTestHelper()
.addInputLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" void test() {",
" Object[] arr = new Object[1];",
" arr[0] = null;",
" }",
"}")
.addOutputLines(
"out/Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" @SuppressWarnings(\"NullAway\")",
" void test() {",
" Object[] arr = new Object[1];",
" arr[0] = null;",
" }",
"}")
.doTest();
}
}

0 comments on commit 43bbb79

Please sign in to comment.