Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@haewiful
Copy link
Contributor

@haewiful haewiful commented Nov 14, 2025

When loading external library models through the ExternalStubxLibraryModels class, it previously didn't parse the method name for methods with wildcard types properly. This PR fixes the method parsing so that it will work for those cases.

The unit test for this is located in java/com/uber/nullaway/jdkannotations/JDKIntegrationTest.java and is libraryLoadMethodParser().

Summary by CodeRabbit

  • New Features

    • Added a new public API method returning a parameterized List (annotated and unannotated variants).
  • Tests

    • Added an integration test covering library parser behavior for return-value handling.
  • Bug Fixes

    • Improved library-model method-signature parsing and normalization to handle irregular spacing/formatting.

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

methodEntry.getKey().substring(methodEntry.getKey().indexOf(" ") + 1);
while (methodNameAndSignature.contains(" ")
&& methodNameAndSignature.indexOf(" ") < methodNameAndSignature.indexOf("(")) {
methodNameAndSignature =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My test case has a NonNull parameter, but passes even without this change. However, since correct parsing is needed, I just added this.

@msridhar msridhar marked this pull request as ready for review November 23, 2025 00:23
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 23, 2025

Walkthrough

Adds a new test method libraryLoadMethodParserReturn() to JDKIntegrationTest.java. Adds getList(Integer, Character) returning List<? super String> to both annotated and unannotated ReturnAnnotation classes (annotated variant marks parameters/return as nullable where shown). In LibraryModelsHandler and ExternalStubxLibraryModels, replaces ad-hoc substring extraction of method name/signature with a shared helper that finds the signature start from the last space before (, trims spaces after commas, strips leading components when necessary, and normalizes method-name/signature handling across nullable-returns and parameter-annotation parsing paths.

Possibly related PRs

Suggested reviewers

  • yuxincs
  • lazaroclapp

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: it identifies a bug fix in the ExternalStubxLibraryModels class related to method name parsing corner cases, which aligns with the PR objectives and code changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 31d0ff7 and 98f5f21.

📒 Files selected for processing (3)
  • jdk-annotations/jdk-integration-test/src/test/java/com/uber/nullaway/jdkannotations/JDKIntegrationTest.java (1 hunks)
  • jdk-annotations/test-annotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.java (2 hunks)
  • nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java (5 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-08-29T18:41:43.584Z
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.

Applied to files:

  • jdk-annotations/test-annotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.java
📚 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:

  • jdk-annotations/test-annotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.java
  • jdk-annotations/jdk-integration-test/src/test/java/com/uber/nullaway/jdkannotations/JDKIntegrationTest.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:

  • jdk-annotations/test-annotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.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:

  • jdk-annotations/jdk-integration-test/src/test/java/com/uber/nullaway/jdkannotations/JDKIntegrationTest.java
🔇 Additional comments (6)
jdk-annotations/test-annotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.java (2)

3-3: LGTM!

The import addition is necessary for the new method signature with wildcard types.


80-83: LGTM!

The new method provides an appropriate test case for the parsing fix, combining:

  • Wildcard type in return: List<? super String>
  • Nullable return annotation
  • Nullable parameter

This signature will exercise the corner case where method name parsing must handle spaces within generic type bounds.

jdk-annotations/jdk-integration-test/src/test/java/com/uber/nullaway/jdkannotations/JDKIntegrationTest.java (1)

333-355: LGTM!

The test correctly verifies that the nullable return annotation is recognized for methods with wildcard types. By dereferencing the result with .isEmpty(), the test ensures that if the parsing succeeds and the nullable return is properly loaded, NullAway will catch the violation and emit the expected diagnostic.

nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java (3)

31-31: LGTM!

The import is necessary for the defensive validation in the new helper method.


1492-1497: LGTM!

The helper method correctly extracts the method name and signature by finding the last space before the opening parenthesis, which handles wildcard types like List<? super String> correctly. The defensive validation with Verify.verify prevents malformed input from causing silent failures.


1445-1456: Verify whitespace normalization consistency across parsing paths.

The inconsistency identified in the review is confirmed. The code applies different whitespace normalization strategies:

  • explicitlyNullableParameters() and nonNullParameters() use .replaceAll(",\\s", ",") to remove only spaces after commas
  • nullableReturns() uses .replaceAll("\\s", "") to remove all whitespace

Since MethodRef equality is based on exact string comparison of the fullMethodSig field (as seen in MethodRef.equals() at line ~282), method signatures with different whitespace normalization will produce different MethodRef keys. For example, a signature like method(Type1, Type2) would become:

  • method(Type1,Type2) via the first strategy
  • method(Type1,Type2) via the second strategy (also, but after removing ALL spaces including any before arguments)

While the three methods currently build independent collections without cross-lookup, this inconsistency is a code quality concern that could cause subtle key mismatches if the code is modified to perform cross-lookups or if additional whitespace patterns appear in method signatures.

Recommend standardizing whitespace normalization across all three methods (lines 1445-1456, 1466-1489, and 1520-1534) to use the same strategy before constructing MethodRef keys, or documenting why different strategies are intentionally required.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java (1)

1415-1427: Method name normalization fix looks correct; consider extracting a shared helper

The new loop that repeatedly strips leading tokens until there are no spaces before the first '(' correctly fixes the case where return types (e.g., with wildcards like List<? super String>) introduce extra spaces before the method name. This brings the stubx-derived methodNameAndSignature into alignment with what MethodRef.fromSymbol expects, without changing behavior for simpler signatures.

The same normalization logic is now duplicated in:

  • explicitlyNullableParameters(...)
  • nonNullParameters(...)
  • nullableReturns(...)

To keep these paths consistent and easier to evolve, consider extracting a small private helper like normalizeMethodNameAndSignature(String rawKey) that:

  • Strips everything before the method name using this loop, and
  • Optionally leaves comma/whitespace post-processing to the individual callers.

That would reduce repetition and the risk of future divergence between parameter and return handling.

Also applies to: 1447-1453, 1501-1507

📜 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 fdec09a and b8bd9f4.

📒 Files selected for processing (4)
  • jdk-annotations/jdk-integration-test/src/test/java/com/uber/nullaway/jdkannotations/JDKIntegrationTest.java (1 hunks)
  • jdk-annotations/test-annotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.java (2 hunks)
  • jdk-annotations/test-unannotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.java (2 hunks)
  • nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java (3 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
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: 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-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:

  • jdk-annotations/test-annotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.java
  • jdk-annotations/jdk-integration-test/src/test/java/com/uber/nullaway/jdkannotations/JDKIntegrationTest.java
📚 Learning: 2025-08-29T18:41:43.584Z
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.

Applied to files:

  • jdk-annotations/test-annotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.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:

  • jdk-annotations/test-annotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.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/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Build and test on macos-latest
  • GitHub Check: Build caffeine with snapshot
  • GitHub Check: Build and test on ubuntu-latest
  • GitHub Check: Build and test on windows-latest
  • GitHub Check: Build spring-framework with snapshot
🔇 Additional comments (2)
jdk-annotations/test-annotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.java (1)

3-6: New annotated getList method correctly models wildcard return for tests

The added imports and getList(@NonNull Integer, @Nullable Character) with @Nullable List<? super String> return cleanly exercise the wildcard-return modeling path without affecting production logic. Looks good as a dedicated fixture for the new integration test.

Also applies to: 82-84

jdk-annotations/test-unannotated/src/main/java/com/uber/nullaway/jdkannotations/ReturnAnnotation.java (1)

3-3: Unannotated getList companion matches annotated fixture as intended

The unannotated getList(Integer, Character) correctly mirrors the annotated version’s signature (sans nullability) and provides the necessary target for stubx-based modeling. No issues spotted.

Also applies to: 71-73

@codecov
Copy link

codecov bot commented Nov 23, 2025

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.39%. Comparing base (feec9d9) to head (98f5f21).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...m/uber/nullaway/handlers/LibraryModelsHandler.java 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1344      +/-   ##
============================================
- Coverage     88.40%   88.39%   -0.02%     
  Complexity     2592     2592              
============================================
  Files            97       97              
  Lines          8701     8702       +1     
  Branches       1731     1732       +1     
============================================
  Hits           7692     7692              
  Misses          505      505              
- Partials        504      505       +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.

return null;
}

public static @Nullable List<? super String> getList(@NonNull Integer i, @Nullable Character c) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this class is @NullMarked you shouldn't need the @NonNull annotation on i

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I will change.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 7803f6c and 5ab331e.

📒 Files selected for processing (1)
  • nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 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.
🔇 Additional comments (3)
nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java (3)

1420-1420: LGTM - maintainer-reviewed extraction.

The use of getMethodNameAndSignature correctly handles wildcard types in method signatures. The subsequent comma-space normalization ensures consistent formatting for MethodRef construction.

Based on past review comments


1441-1441: LGTM - consistent with parameter handling pattern.

Correctly applies getMethodNameAndSignature with the same whitespace normalization approach used in explicitlyNullableParameters.


1493-1498: Clarify the need for additional stripping logic.

After calling getMethodNameAndSignature (which finds the last space before '('), this while loop continues to strip leading components if spaces remain before '('. This suggests either:

  1. getMethodNameAndSignature doesn't fully handle certain edge cases, or
  2. This is defensive/redundant code

Additionally, nullableReturns removes ALL whitespace (line 1506: replaceAll("\\s", "")), while parameter methods only remove spaces after commas.

Can you clarify:

  • Why is the while loop necessary after getMethodNameAndSignature has already extracted from the last space before '('?
  • Why does nullableReturns require different whitespace normalization than the parameter methods?

If the while loop is defensive but not strictly necessary, consider adding a comment explaining the edge cases it handles. If it's truly redundant given the helper's logic, it could be removed for consistency with the parameter methods.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 5ab331e and 31d0ff7.

📒 Files selected for processing (1)
  • nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 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.
🔇 Additional comments (3)
nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java (3)

1468-1473: LGTM: Well-implemented helper method.

The helper correctly extracts the method name and signature by finding the last space before the opening parenthesis. The Verify.verify() provides adequate defensive validation for malformed input.

Based on past review comments, the maintainer has already reviewed and simplified this logic.


1421-1421: LGTM: Correct usage of the helper method.

The helper is properly used to extract the method name and signature, followed by appropriate normalization to remove spaces after commas in the parameter list.


1442-1442: LGTM: Consistent implementation with explicitlyNullableParameters().

The same pattern is correctly applied here - extract method name and signature, then normalize by removing spaces after commas.

@msridhar msridhar enabled auto-merge (squash) November 24, 2025 18:08
@msridhar msridhar merged commit 585b40e into uber:master Nov 24, 2025
10 of 11 checks passed
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.

2 participants