-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash with suggested suppressions in JSpecify mode (#1001)
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
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
nullaway/src/test/java/com/uber/nullaway/jspecify/SuggestedFixesTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |