Skip to content

Allow suppressing nullaway on individual parameters - #1436

Merged
msridhar merged 8 commits into
apache:masterfrom
jackwickham:jackwickham/suppress-on-param
Jan 15, 2026
Merged

msridhar merged 8 commits into
apache:masterfrom
jackwickham:jackwickham/suppress-on-param

Conversation

@jackwickham

@jackwickham jackwickham commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

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:

import com.google.common.util.concurrent.FutureCallback;

public final class Repro implements FutureCallback<String> {
    @Override
    public void onSuccess(@SuppressWarnings("NullAway") String result) {
        System.out.println(result);
    }

    @Override
    public void onFailure(Throwable t) {
        t.printStackTrace();
    }
}

Input requested

  • I've added a test, but am not sure if this is the best place to put it, or if we want more test coverage. There doesn't seem to be loads of test coverage for suppression specifically.

Summary by CodeRabbit

  • Bug Fixes

    • More accurate error reporting for parameter override nullability mismatches, preserving use-site suppression context when available.
  • Tests

    • Updated test expectations to reflect new source positions.
    • Replaced an older suppression test with a comprehensive suppression test suite covering suppression aliases and behavior for parameters, method references, and lambdas.

✏️ Tip: You can customize this high-level summary in your review settings.

@CLAassistant

CLAassistant commented Jan 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Compute 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

  • msridhar
  • yuxincs
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Allow suppressing nullaway on individual parameters' clearly summarizes the main change, which enables @SuppressWarnings suppression at the parameter level rather than just method level.
Linked Issues check ✅ Passed The PR implements all coding requirements from issue #1433: parameter-level @SuppressWarnings suppression for WRONG_OVERRIDE_PARAM errors, with comprehensive test coverage including functional interfaces, lambdas, and method references.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective: NullAway.java implements per-parameter suppression logic, SerializationTest.java updates line numbers to match, and SuppressionTests.java provides comprehensive test coverage for the new functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1cdc5fb and efae0d4.

📒 Files selected for processing (1)
  • nullaway/src/main/java/com/uber/nullaway/NullAway.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.
📚 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/main/java/com/uber/nullaway/NullAway.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)

929-942: LGTM! Clean implementation of per-parameter suppression with proper null handling.

The logic correctly distinguishes between:

  1. Member references: Uses the original state since suppression should be on the use site (where the method reference is written)
  2. Lambdas and regular overrides: Uses state.withPath(path) when available, enabling @SuppressWarnings("NullAway") directly on the parameter

The null check on line 936 properly handles the edge case where getPath(paramSymbol) returns null for binary/library method parameters, addressing the concern from the previous review.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 80fbdc9 and 75d57b7.

📒 Files selected for processing (2)
  • nullaway/src/main/java/com/uber/nullaway/NullAway.java
  • nullaway/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.java
  • nullaway/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.java
  • nullaway/src/main/java/com/uber/nullaway/NullAway.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 75d57b7 and a04cfdd.

📒 Files selected for processing (2)
  • nullaway/src/main/java/com/uber/nullaway/NullAway.java
  • nullaway/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.java
  • nullaway/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 via state.withPath(path), but please sanity-check cross-compilation-unit paths.

Line 908 / Line 912: Wiring the VisitorState to the parameter’s TreePath should make @SuppressWarnings("NullAway") on that parameter suppress WRONG_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 current state; if Error Prone assumes same-CU paths here, this could cause brittle behavior.

Optional cleanup: cache Trees once.

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);

Comment on lines +1299 to +1346
@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();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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
msridhar previously approved these changes Jan 12, 2026

@msridhar msridhar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice clean fix, thank you @jackwickham!

@msridhar

Copy link
Copy Markdown
Contributor

@jackwickham are you able to sign the CLA? We'll need that before we can accept this change. Thanks!

@msridhar
msridhar enabled auto-merge (squash) January 12, 2026 15:59
auto-merge was automatically disabled January 12, 2026 16:39

Head branch was pushed to by a user without write access

@jackwickham

Copy link
Copy Markdown
Contributor Author

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a04cfdd and 98b02eb.

📒 Files selected for processing (3)
  • nullaway/src/main/java/com/uber/nullaway/NullAway.java
  • nullaway/src/test/java/com/uber/nullaway/CoreTests.java
  • nullaway/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.java
  • nullaway/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.java
  • nullaway/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)) for WRONG_OVERRIDE_PARAM should 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 errorTree against null (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_PARAM look consistent with the checker now associating the diagnostic with the parameter’s path/state.

Also applies to: 1271-1287

Comment on lines +1299 to +1420
@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();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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 withPath logic likely enables it.
  • If test organization becomes a concern, consider moving these into a dedicated suppression-focused test class; otherwise CoreTests is fine.

@msridhar msridhar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@msridhar
msridhar self-requested a review January 12, 2026 17:25
@msridhar
msridhar dismissed their stale review January 12, 2026 17:25

Further comments

@codecov

codecov Bot commented Jan 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.36%. Comparing base (d594809) to head (efae0d4).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...away/src/main/java/com/uber/nullaway/NullAway.java 75.00% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@msridhar

Copy link
Copy Markdown
Contributor

@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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 98b02eb and 4591160.

📒 Files selected for processing (2)
  • nullaway/src/test/java/com/uber/nullaway/SuppressionNameAliasesTests.java
  • nullaway/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.

@jackwickham

Copy link
Copy Markdown
Contributor Author

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.

@msridhar

Copy link
Copy Markdown
Contributor

Having the codecov checks not pass is fine.

@jackwickham

Copy link
Copy Markdown
Contributor Author

CLA signed, should be good to merge now (sorry for the delay!)

@msridhar
msridhar enabled auto-merge (squash) January 15, 2026 15:07
@msridhar

Copy link
Copy Markdown
Contributor

Thanks @jackwickham for the fix!

@msridhar
msridhar merged commit 1ca1b25 into apache:master Jan 15, 2026
@jackwickham

Copy link
Copy Markdown
Contributor Author

Thanks for the quick turnaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@SuppressWarnings on method parameter does not suppress warnings about superclass type being @Nullable

3 participants