Repository navigation
Allow suppressing nullaway on individual parameters #1436
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
Merged
msridhar
merged 8 commits into
apache:master
from
jackwickham:jackwickham/suppress-on-param
Jan 15, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f510b82
Allow suppressing nullaway on individual parameters
jackwickham 75d57b7
Bit of manual formatting
jackwickham a04cfdd
Use the suggested llm prompt to implement fixes to the nits
jackwickham 98b02eb
Fix functional interface handling
jackwickham 5970161
CR
jackwickham 4591160
Add tests for lambdas too
jackwickham 1cdc5fb
Fix test to check the correct diagnostic
jackwickham efae0d4
Merge branch 'master' into jackwickham/suppress-on-param
jackwickham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
39 changes: 0 additions & 39 deletions
39
nullaway/src/test/java/com/uber/nullaway/SuppressionNameAliasesTests.java
This file was deleted.
Oops, something went wrong.
219 changes: 219 additions & 0 deletions
219
nullaway/src/test/java/com/uber/nullaway/SuppressionTests.java
This file contains hidden or 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,219 @@ | ||
| package com.uber.nullaway; | ||
|
|
||
| import java.util.Arrays; | ||
| import org.junit.Test; | ||
|
|
||
| public class SuppressionTests extends NullAwayTestsBase { | ||
|
|
||
| @Test | ||
| public void additionalSuppressionNamesTest() { | ||
| makeTestHelperWithArgs( | ||
| Arrays.asList( | ||
| "-d", | ||
| temporaryFolder.getRoot().getAbsolutePath(), | ||
| "-XepOpt:NullAway:AnnotatedPackages=com.uber", | ||
| "-XepOpt:NullAway:SuppressionNameAliases=Foo,Bar")) | ||
| .addSourceLines( | ||
| "Test.java", | ||
| """ | ||
| package com.uber; | ||
| import org.jspecify.annotations.Nullable; | ||
| class Test { | ||
| @SuppressWarnings("Foo") | ||
| void foo(@Nullable Object o) { | ||
| o.getClass(); | ||
| } | ||
| @SuppressWarnings("Bar") | ||
| void bar(@Nullable Object o) { | ||
| o.getClass(); | ||
| } | ||
| @SuppressWarnings("Baz") | ||
| void baz(@Nullable Object o) { | ||
| // BUG: Diagnostic contains: dereferenced expression o is @Nullable | ||
| o.getClass(); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void wrongOverrideParamSuppressionOnParameter() { | ||
| defaultCompilationHelper | ||
| .addSourceLines( | ||
| "TestInterface.java", | ||
| """ | ||
| package com.uber; | ||
| import javax.annotation.Nullable; | ||
| public interface TestInterface { | ||
| void foo(@Nullable Object param); | ||
| } | ||
| """) | ||
| .addSourceLines( | ||
| "TestImpl.java", | ||
| """ | ||
| package com.uber; | ||
| public class TestImpl implements TestInterface { | ||
| @Override | ||
| public void foo(@SuppressWarnings("NullAway") Object param) {} | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void wrongOverrideParamSuppressionOnMethodReferenceUsage() { | ||
| defaultCompilationHelper | ||
| .addSourceLines( | ||
| "TestInterface.java", | ||
| """ | ||
| package com.uber; | ||
| import javax.annotation.Nullable; | ||
| public interface TestInterface { | ||
| void foo(@Nullable Object param); | ||
| } | ||
| """) | ||
| .addSourceLines( | ||
| "TestImpl.java", | ||
| """ | ||
| package com.uber; | ||
| public class TestImpl { | ||
| public void doFoo(Object param) {} | ||
| } | ||
| """) | ||
| .addSourceLines( | ||
| "TestDriver.java", | ||
| """ | ||
| package com.uber; | ||
| public class TestDriver { | ||
| public int bar(TestInterface param) { | ||
| return 0; | ||
| } | ||
| public void doTest(TestImpl impl) { | ||
| @SuppressWarnings("NullAway") | ||
| int res = bar(impl::doFoo); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void wrongOverrideParamSuppressionOnLambda() { | ||
| defaultCompilationHelper | ||
| .addSourceLines( | ||
| "TestInterface.java", | ||
| """ | ||
| package com.uber; | ||
| import javax.annotation.Nullable; | ||
| public interface TestInterface { | ||
| void foo(@Nullable Object param); | ||
| } | ||
| """) | ||
| .addSourceLines( | ||
| "TestDriver.java", | ||
| """ | ||
| package com.uber; | ||
| public class TestDriver { | ||
| public int bar(TestInterface param) { | ||
| return 0; | ||
| } | ||
| public void doTest() { | ||
| int res = bar((@SuppressWarnings("NullAway") Object param) -> {}); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void wrongOverrideParamNoSuppression() { | ||
| defaultCompilationHelper | ||
| .addSourceLines( | ||
| "TestInterface.java", | ||
| """ | ||
| package com.uber; | ||
| import javax.annotation.Nullable; | ||
| public interface TestInterface { | ||
| void foo(@Nullable Object param); | ||
| } | ||
| """) | ||
| .addSourceLines( | ||
| "TestImpl.java", | ||
| """ | ||
| package com.uber; | ||
| public class TestImpl implements TestInterface { | ||
| @Override | ||
| // BUG: Diagnostic contains: parameter param is @NonNull, but parameter in superclass method | ||
| public void foo(Object param) {} | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void wrongOverrideParamOnMethodReferenceUsageNoSuppression() { | ||
| defaultCompilationHelper | ||
| .addSourceLines( | ||
| "TestInterface.java", | ||
| """ | ||
| package com.uber; | ||
| import javax.annotation.Nullable; | ||
| public interface TestInterface { | ||
| void foo(@Nullable Object param); | ||
| } | ||
| """) | ||
| .addSourceLines( | ||
| "TestImpl.java", | ||
| """ | ||
| package com.uber; | ||
| public class TestImpl { | ||
| public void doFoo(Object param) {} | ||
| } | ||
| """) | ||
| .addSourceLines( | ||
| "TestDriver.java", | ||
| """ | ||
| package com.uber; | ||
| public class TestDriver { | ||
| public int bar(TestInterface param) { | ||
| return 0; | ||
| } | ||
| public void doTest(TestImpl impl) { | ||
| // BUG: Diagnostic contains: parameter param of referenced method is @NonNull, but parameter in functional interface method | ||
| int res = bar(impl::doFoo); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void wrongOverrideParamOnLambdaNoSuppression() { | ||
| defaultCompilationHelper | ||
| .addSourceLines( | ||
| "TestInterface.java", | ||
| """ | ||
| package com.uber; | ||
| import javax.annotation.Nullable; | ||
| public interface TestInterface { | ||
| void foo(@Nullable Object param); | ||
| } | ||
| """) | ||
| .addSourceLines( | ||
| "TestDriver.java", | ||
| """ | ||
| package com.uber; | ||
| public class TestDriver { | ||
| public int bar(TestInterface param) { | ||
| return 0; | ||
| } | ||
| public void doTest() { | ||
| // BUG: Diagnostic contains: parameter param is @NonNull, but parameter in functional interface method | ||
| int res = bar((Object param) -> {}); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.