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

Skip to content

Conversation

@msridhar
Copy link
Collaborator

@msridhar msridhar commented Aug 28, 2025

Fixes #1264

Summary by CodeRabbit

  • Bug Fixes
    • Improved robustness when analyzing generic method types to prevent rare crashes; safer method-type handling reduces risk of ClassCastExceptions.
  • Tests
    • Added a test covering inheritance with raw-type overrides to ensure stable behavior and prevent regressions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 28, 2025

Walkthrough

Replaces a direct cast with a safe accessor when extracting a MethodType in RestoreNullnessAnnotationsVisitor.visitMethodType, and adds a jspecify test to exercise overriding with raw types to prevent a ClassCastException.

Changes

Cohort / File(s) Summary
Generics nullness visitor
nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java
Replace direct cast to Type.MethodType with other.asMethodType() in RestoreNullnessAnnotationsVisitor.visitMethodType; remaining logic for visiting parameter, return, and thrown types unchanged.
JSpecify generic inheritance tests
nullaway/src/test/java/com/uber/nullaway/jspecify/GenericInheritanceTests.java
Add overrideWithRawTypes() test to reproduce/validate handling of a method overridden with raw types (issue #1264 scenario) and ensure no crash under @NullMarked.

Sequence Diagram(s)

(omitted — changes are a localized type-access adjustment and a unit test; no new multi-component control flow to diagram)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Reproduce and fix the ClassCastException when javac presents a ForAll vs MethodType (issue #1264)
Determine/modify the method signature or otherwise resolve the underlying generic/raw return mismatch (#1264) No change to method signatures or API; only a safe accessor was added.
Apply a minimal targeted remediation to avoid the crash while preserving semantics (#1264)
Ensure compilation under ErrorProne + NullAway + jspecify without broad disabling (#1264)

Suggested reviewers

  • yuxincs

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 41ef2c4 and ebef64f.

📒 Files selected for processing (2)
  • nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java (1 hunks)
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericInheritanceTests.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericInheritanceTests.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). (8)
  • GitHub Check: Build caffeine with snapshot
  • GitHub Check: JDK 11 on ubuntu-latest with Error Prone 2.31.0
  • GitHub Check: JDK 17 on ubuntu-latest with Error Prone 2.41.0
  • GitHub Check: JDK 17 on windows-latest with Error Prone 2.41.0
  • GitHub Check: JDK 17 on ubuntu-latest with Error Prone 2.14.0
  • GitHub Check: Build spring-framework with snapshot
  • GitHub Check: JDK 17 on macos-latest with Error Prone 2.41.0
  • GitHub Check: JDK 11 on ubuntu-latest with Error Prone 2.14.0
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch issue-1264

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (3)
nullaway/src/test/java/com/uber/nullaway/jspecify/GenericInheritanceTests.java (2)

210-213: Fix incorrect issue reference in doc comment

The PR fixes issue 1264, but the test comment says 1250. Update to avoid confusion.

-  /** For issue 1250. Checks that we don't crash when overriding with raw types. */
+  /** For issue 1264. Checks that we don't crash when overriding with raw types. */

210-233: Optional: add a variant covering thrown types to harden the fix

A second test where the base method declares checked exceptions ensures visitMethodType’s thrown list handling stays robust with raw overrides.

+  @Test
+  public void overrideWithRawTypes_andThrows() {
+    makeHelper()
+        .addSourceLines(
+            "Test.java",
+            "import org.jspecify.annotations.NullMarked;",
+            "@NullMarked",
+            "public class Test {",
+            "  static class A<T> {}",
+            "  static class B<T> {",
+            "    public <X> X accept(A<X> a) throws Exception {",
+            "      throw new RuntimeException();",
+            "    }",
+            "  }",
+            "  static class Raw extends B {",
+            "    @Override",
+            "    public Object accept(A a) throws Exception {",
+            "      throw new RuntimeException();",
+            "    }",
+            "  }",
+            "}")
+        .doTest();
+  }
nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java (1)

84-85: Nit: document why asMethodType() is needed here

A short comment helps future maintainers understand the ForAll wrapping case.

-      Type.MethodType otherMethodType = other.asMethodType();
+      // other can be a ForAll whose qtype is a MethodType; asMethodType() safely unwraps it.
+      Type.MethodType otherMethodType = other.asMethodType();
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d0e9bbb and 41ef2c4.

📒 Files selected for processing (2)
  • nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java (1 hunks)
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericInheritanceTests.java (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: msridhar
PR: uber/NullAway#1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.922Z
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
PR: uber/NullAway#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-28T04:54:20.922Z
Learnt from: msridhar
PR: uber/NullAway#1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.922Z
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/generics/TypeSubstitutionUtils.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericInheritanceTests.java
📚 Learning: 2025-08-14T18:50:06.159Z
Learnt from: msridhar
PR: uber/NullAway#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/jspecify/GenericInheritanceTests.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). (8)
  • GitHub Check: JDK 17 on windows-latest with Error Prone 2.41.0
  • GitHub Check: JDK 17 on ubuntu-latest with Error Prone 2.41.0
  • GitHub Check: JDK 17 on macos-latest with Error Prone 2.41.0
  • GitHub Check: JDK 17 on ubuntu-latest with Error Prone 2.14.0
  • GitHub Check: JDK 11 on ubuntu-latest with Error Prone 2.14.0
  • GitHub Check: JDK 11 on ubuntu-latest with Error Prone 2.31.0
  • GitHub Check: Build caffeine with snapshot
  • GitHub Check: Build spring-framework with snapshot
🔇 Additional comments (2)
nullaway/src/test/java/com/uber/nullaway/jspecify/GenericInheritanceTests.java (1)

210-233: Regression test for raw override crash — LGTM

Accurately reproduces the scenario and guards against regressions (no diagnostics, no crash).

nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java (1)

84-91: Use of asMethodType() prevents CCE when ‘other’ is ForAll — LGTM

This aligns with javac’s shape and fixes the raw-override crash path.

@codecov
Copy link

codecov bot commented Aug 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.17%. Comparing base (d0e9bbb) to head (ebef64f).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1265   +/-   ##
=========================================
  Coverage     88.17%   88.17%           
  Complexity     2427     2427           
=========================================
  Files            92       92           
  Lines          8010     8010           
  Branches       1595     1595           
=========================================
  Hits           7063     7063           
  Misses          492      492           
  Partials        455      455           

☔ 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 msridhar merged commit cf02218 into master Aug 28, 2025
14 checks passed
@msridhar msridhar deleted the issue-1264 branch August 28, 2025 20:43
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.

Exception when have workaround because type erasure on JVM

3 participants