Repository navigation
Allow suppressing nullaway on individual parameters - #1436
Conversation
WalkthroughCompute and attach a context-aware error state when reporting WRONG_OVERRIDE_PARAM in checkParamOverriding: if a method reference is present, keep the original state; otherwise derive a TreePath for the overridden parameter symbol and use state.withPath(path) when available. The error description is produced with this param-specific state. Tests were reorganized: a new SuppressionTests class was added covering suppression aliases and various override/lambda/method-reference scenarios, one old test file was removed, and two test expectation line numbers were updated. Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (3)📓 Common learnings📚 Learning: 2025-08-28T04:54:20.953ZApplied to files:
📚 Learning: 2025-12-31T23:59:20.009ZApplied to files:
🔇 Additional comments (1)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @nullaway/src/main/java/com/uber/nullaway/NullAway.java:
- Around line 908-912: The call to
state.withPath(getTreesInstance(state).getPath(paramSymbol)) can receive a null
TreePath for binary/library member references; retrieve the TreePath into a
local (e.g., TreePath path = getTreesInstance(state).getPath(paramSymbol)) and
check for null, using state.withPath(path) only if path != null, otherwise use
the original state when calling errorBuilder.createErrorDescription (keep the
same ErrorMessage, buildDescription(errorTree), and paramSymbol).
In @nullaway/src/test/java/com/uber/nullaway/CoreTests.java:
- Around line 1298-1321: Add a complementary negative test next to
wrongOverrideParamSuppressionOnParameter: create a new test method
wrongOverrideParamNoSuppression that uses defaultCompilationHelper to add the
same TestInterface and TestImpl sources but without @SuppressWarnings on the
overriding parameter, and annotate the overriding method with the BUG:
Diagnostic comment (containing the expected WRONG_OVERRIDE_PARAM message such as
"parameter param is @NonNull, but parameter in superclass method") so the test
asserts the warning is emitted; mirror the existing test structure and finish
with .doTest().
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
nullaway/src/main/java/com/uber/nullaway/NullAway.javanullaway/src/test/java/com/uber/nullaway/CoreTests.java
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Learnt from: msridhar
Repo: uber/NullAway PR: 1316
File: jdk-javac-plugin/src/main/java/com/uber/nullaway/javacplugin/NullnessAnnotationSerializer.java:261-293
Timestamp: 2025-10-29T23:56:18.236Z
Learning: In NullAway's jdk-javac-plugin NullnessAnnotationSerializer, type variable bounds with annotations (e.g., `T extends Nullable Object`) are checked at their declaration sites by the typeParamHasAnnotation method for both class-level and method-level type parameters. The hasJSpecifyAnnotationDeep method is designed to check type uses (return types, parameters, etc.) and does not need a TYPEVAR case because type variable declaration bounds are already handled separately.
Learnt from: msridhar
Repo: uber/NullAway PR: 1259
File: jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/SwitchTests.java:318-321
Timestamp: 2025-08-29T18:41:43.584Z
Learning: Classes annotated with NullMarked are analyzed by NullAway even if they are not in packages specified by the AnnotatedPackages configuration. The NullMarked annotation guarantees NullAway analysis.
📚 Learning: 2025-08-14T18:50:06.159Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/main/java/com/uber/nullaway/NullAway.java
📚 Learning: 2025-08-28T04:54:20.953Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/main/java/com/uber/nullaway/NullAway.java
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @nullaway/src/test/java/com/uber/nullaway/CoreTests.java:
- Around line 1299-1346: The test wrongOverrideParamNoSuppression asserts a
diagnostic message that says "parameter in superclass method" but the overridden
method is declared in an interface; update the expected diagnostic comment in
the wrongOverrideParamNoSuppression test (the BUG: Diagnostic contains: ... line
above public void foo(Object param)) to use wording matching the code context
(e.g., "parameter in superinterface method" or "parameter in supertype method")
so the expectation correctly reflects an interface override.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
nullaway/src/main/java/com/uber/nullaway/NullAway.javanullaway/src/test/java/com/uber/nullaway/CoreTests.java
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
📚 Learning: 2025-08-14T18:50:06.159Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-08-28T04:54:20.953Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/main/java/com/uber/nullaway/NullAway.java
📚 Learning: 2025-10-29T23:56:18.236Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1316
File: jdk-javac-plugin/src/main/java/com/uber/nullaway/javacplugin/NullnessAnnotationSerializer.java:261-293
Timestamp: 2025-10-29T23:56:18.236Z
Learning: In NullAway's jdk-javac-plugin NullnessAnnotationSerializer, type variable bounds with annotations (e.g., `T extends Nullable Object`) are checked at their declaration sites by the typeParamHasAnnotation method for both class-level and method-level type parameters. The hasJSpecifyAnnotationDeep method is designed to check type uses (return types, parameters, etc.) and does not need a TYPEVAR case because type variable declaration bounds are already handled separately.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-12-31T23:59:20.009Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1421
File: nullaway/src/main/java/com/uber/nullaway/NullAway.java:339-340
Timestamp: 2025-12-31T23:59:20.009Z
Learning: In Error Prone's ASTHelpers class, the getSymbol(MethodInvocationTree) overload is guaranteed to return a non-null Symbol.MethodSymbol. This differs from other overloads of getSymbol() that may return null. Therefore, no null check is required after calling ASTHelpers.getSymbol() with a MethodInvocationTree parameter.
Applied to files:
nullaway/src/main/java/com/uber/nullaway/NullAway.java
🔇 Additional comments (1)
nullaway/src/main/java/com/uber/nullaway/NullAway.java (1)
902-914: Per-parameter suppression looks correctly enabled viastate.withPath(path), but please sanity-check cross-compilation-unit paths.Line 908 / Line 912: Wiring the
VisitorStateto the parameter’sTreePathshould make@SuppressWarnings("NullAway")on that parameter suppressWRONG_OVERRIDE_PARAM, which matches the PR goal. One concern: in the member-reference flow,Trees.getPath(paramSymbol)could (in theory) return a path rooted in a different compilation unit than the currentstate; if Error Prone assumes same-CU paths here, this could cause brittle behavior.Optional cleanup: cache
Treesonce.Proposed small refactor (no behavior change intended)
- Tree errorTree; - if (memberReferenceTree != null) { - errorTree = memberReferenceTree; - } else { - errorTree = getTreesInstance(state).getTree(paramSymbol); - } - TreePath path = getTreesInstance(state).getPath(paramSymbol); + Trees trees = getTreesInstance(state); + Tree errorTree; + if (memberReferenceTree != null) { + errorTree = memberReferenceTree; + } else { + errorTree = trees.getTree(paramSymbol); + } + TreePath path = trees.getPath(paramSymbol); + VisitorState stateWithParamPath = path != null ? state.withPath(path) : state; return errorBuilder.createErrorDescription( new ErrorMessage(MessageTypes.WRONG_OVERRIDE_PARAM, message), buildDescription(errorTree), - path != null ? state.withPath(path) : state, + stateWithParamPath, paramSymbol);
| @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 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(); | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Tests cover the regression well; consider a real-world FutureCallback#onSuccess variant (optional) and confirm desired wording.
Lines 1299-1346: The pair of tests cleanly checks (1) parameter-level suppression works, and (2) the diagnostic still triggers without suppression. One small note: the expected message uses “superclass method” though the overridden member is in an interface (Line 1341-1342). If you intend to keep this wording, the test is fine as-is; otherwise, update message + expectation together.
🤖 Prompt for AI Agents
In @nullaway/src/test/java/com/uber/nullaway/CoreTests.java around lines 1299 -
1346, The test wrongOverrideParamNoSuppression asserts a diagnostic message that
says "parameter in superclass method" but the overridden method is declared in
an interface; update the expected diagnostic comment in the
wrongOverrideParamNoSuppression test (the BUG: Diagnostic contains: ... line
above public void foo(Object param)) to use wording matching the code context
(e.g., "parameter in superinterface method" or "parameter in supertype method")
so the expectation correctly reflects an interface override.
msridhar
left a comment
There was a problem hiding this comment.
Nice clean fix, thank you @jackwickham!
|
@jackwickham are you able to sign the CLA? We'll need that before we can accept this change. Thanks! |
Head branch was pushed to by a user without write access
|
I realised this wasn't handling functional interfaces properly, so I've had to make it slightly uglier (and added a test for that). I'm still waiting on a legal stamp before signing the CLA, you were quicker to review than I expected :D |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (3)
nullaway/src/main/java/com/uber/nullaway/NullAway.javanullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/test/java/com/uber/nullaway/SerializationTest.java
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
📚 Learning: 2025-08-14T18:50:06.159Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/test/java/com/uber/nullaway/SerializationTest.java
📚 Learning: 2025-08-28T04:54:20.953Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/main/java/com/uber/nullaway/NullAway.java
📚 Learning: 2025-11-25T22:43:06.446Z
Learnt from: CR
Repo: uber/NullAway PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T22:43:06.446Z
Learning: Run only the tests for the main NullAway module using `./gradlew :nullaway:test` unless specifically asked to run tests in a different module
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-12-31T23:59:20.009Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1421
File: nullaway/src/main/java/com/uber/nullaway/NullAway.java:339-340
Timestamp: 2025-12-31T23:59:20.009Z
Learning: In Error Prone's ASTHelpers class, the getSymbol(MethodInvocationTree) overload is guaranteed to return a non-null Symbol.MethodSymbol. This differs from other overloads of getSymbol() that may return null. Therefore, no null check is required after calling ASTHelpers.getSymbol() with a MethodInvocationTree parameter.
Applied to files:
nullaway/src/main/java/com/uber/nullaway/NullAway.java
🔇 Additional comments (2)
nullaway/src/main/java/com/uber/nullaway/NullAway.java (1)
902-921: Good fix for parameter-level suppression; consider minor hardening + verify Error Prone API compatibility.Using
state.withPath(getTreesInstance(state).getPath(paramSymbol))forWRONG_OVERRIDE_PARAMshould make@SuppressWarnings("NullAway")on the parameter take effect, while keeping member refs as use-site suppression only—this matches the PR goal.Two small improvements:
- Avoid repeated
getTreesInstance(state)calls in this error path (tiny readability win).- Consider guarding
errorTreeagainstnull(fallback to the enclosing method tree) to prevent a potential NPE if this ever gets invoked with symbols lacking source trees.Proposed diff (minor refactor + null-safe fallback)
Tree errorTree; + Trees trees = getTreesInstance(state); if (memberReferenceTree != null) { errorTree = memberReferenceTree; } else { - errorTree = getTreesInstance(state).getTree(paramSymbol); + errorTree = trees.getTree(paramSymbol); } VisitorState paramState; if (memberReferenceTree != null) { // For nullability issues related to functional interfaces, the suppression should be on // the use site paramState = state; } else { - TreePath path = getTreesInstance(state).getPath(paramSymbol); + TreePath path = trees.getPath(paramSymbol); paramState = path != null ? state.withPath(path) : state; } + if (errorTree == null) { + // Defensive fallback; should be rare/unreachable for source-backed symbols. + errorTree = trees.getTree(overridingMethod); + } return errorBuilder.createErrorDescription( new ErrorMessage(MessageTypes.WRONG_OVERRIDE_PARAM, message), buildDescription(errorTree), paramState, paramSymbol);Also please verify the minimal supported Error Prone version for NullAway includes
VisitorState.withPath(TreePath)and that suppression resolution behaves as expected with it.nullaway/src/test/java/com/uber/nullaway/SerializationTest.java (1)
314-330: Expected serialization positions updated appropriately for new diagnostic anchoring.The adjusted expected positions for
WRONG_OVERRIDE_PARAMlook consistent with the checker now associating the diagnostic with the parameter’s path/state.Also applies to: 1271-1287
| @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 wrongOverrideParamSuppressionOnLambdaUsage() { | ||
| 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 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 wrongOverrideParamOnLambdaUsageNoSuppression() { | ||
| 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(); | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Tests cover the intended behavior (parameter suppression + use-site suppression for method refs).
These four cases are a solid regression suite for the change, including the “no suppression” negatives.
Optional follow-ups:
- Add a test for suppression placed directly on a typed lambda parameter (not just a method reference / use-site suppression), since the new
withPathlogic likely enables it. - If test organization becomes a concern, consider moving these into a dedicated suppression-focused test class; otherwise
CoreTestsis fine.
msridhar
left a comment
There was a problem hiding this comment.
If we want to handle more cases, there are also explicitly-typed lambda parameters. E.g., this example still gives a warning in NullAway 0.12.15:
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.function.Function;
@NullMarked
class Scratch {
public static void main(String[] args) {
Function<@Nullable String, String> f = (@SuppressWarnings("NullAway") String s) -> s == null ? "default" : s;
}
}This will be less common so if it's hard to handle I'm ok with skipping.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1436 +/- ##
============================================
- Coverage 88.37% 88.36% -0.01%
- Complexity 2680 2681 +1
============================================
Files 97 97
Lines 8878 8882 +4
Branches 1777 1779 +2
============================================
+ Hits 7846 7849 +3
Misses 511 511
- Partials 521 522 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@jackwickham do you have a rough idea of when you might get back to this? We're thinking about cutting a release soonish, and I figured it might be helpful to you all to get this change in. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@nullaway/src/test/java/com/uber/nullaway/SuppressionTests.java`:
- Line 212: The lambda in the call to bar is missing its opening parenthesis;
update the expression passed to bar so the parameter list is properly
parenthesized as (Object param) -> {} (i.e., fix the argument to bar in
SuppressionTests.java so the lambda is written as (Object param) -> {}).
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
nullaway/src/test/java/com/uber/nullaway/SuppressionNameAliasesTests.javanullaway/src/test/java/com/uber/nullaway/SuppressionTests.java
💤 Files with no reviewable changes (1)
- nullaway/src/test/java/com/uber/nullaway/SuppressionNameAliasesTests.java
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
📚 Learning: 2025-08-14T18:50:06.159Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/SuppressionTests.java
📚 Learning: 2025-08-28T04:54:20.953Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/SuppressionTests.java
📚 Learning: 2025-11-25T22:43:06.446Z
Learnt from: CR
Repo: uber/NullAway PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T22:43:06.446Z
Learning: Use the `--tests` flag with gradle to run specific test classes or methods, e.g., `./gradlew :nullaway:test --tests "com.uber.nullaway.NullAwayTest"`
Applied to files:
nullaway/src/test/java/com/uber/nullaway/SuppressionTests.java
📚 Learning: 2025-11-25T22:43:06.446Z
Learnt from: CR
Repo: uber/NullAway PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T22:43:06.446Z
Learning: Run only the tests for the main NullAway module using `./gradlew :nullaway:test` unless specifically asked to run tests in a different module
Applied to files:
nullaway/src/test/java/com/uber/nullaway/SuppressionTests.java
🔇 Additional comments (1)
nullaway/src/test/java/com/uber/nullaway/SuppressionTests.java (1)
1-38: Good test coverage for the PR objectives.The test class effectively covers the core functionality: parameter-level
@SuppressWarnings("NullAway")for override parameter type mismatches, suppression at method reference use-sites, lambda parameters, and suppression name aliases. The paired "no suppression" tests ensure the warnings still fire when suppression is absent.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
|
Looks like the fix already covered lambdas, added a test for that too (and moved the tests to a separate file to keep them together, next to another suppression test). I hope to get the CLA sorted today or tomorrow, and should be able to address any other comments by tomorrow too. I don't think the codecov checks will pass because the branch that's missing I don't think is possible to hit in reasonable code, it's just being defensive against nulls. I could have it throw, but I don't know for sure that it's unreachable. |
|
Having the codecov checks not pass is fine. |
|
CLA signed, should be good to merge now (sorry for the delay!) |
|
Thanks @jackwickham for the fix! |
|
Thanks for the quick turnaround! |
Fixes #1433
Currently it's not possible to suppress warnings about overriding a NonNull parameter as Nullable on a per-parameter basis, only on the whole method.
This PR fixes that.
That enables this code to compile:
Input requested
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.