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 crash with suggested suppressions in JSpecify mode #1001

Merged
merged 2 commits into from
Jul 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
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();
}
}