-
Notifications
You must be signed in to change notification settings - Fork 329
JSpecify: Fix crash when overriding with raw types #1265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughReplaces 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
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
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 commentThe 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 fixA 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 hereA 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.
📒 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.javanullaway/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 — LGTMAccurately 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 — LGTMThis aligns with javac’s shape and fixes the raw-override crash path.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Fixes #1264
Summary by CodeRabbit