Add more instance fields to GenericsChecks#1256
Conversation
WalkthroughRefactors GenericsChecks from static-style utilities to an instance bound to NullAway, Config, and Handler. NullAway now constructs and stores GenericsChecks in its constructors and updates all call sites to use instance methods with reduced parameters. Dependent classes adjust constructors/usages accordingly. No public-facing behavior changes declared. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Compiler
participant NA as NullAway
participant GC as GenericsChecks
participant DF as AccessPathNullnessPropagation
note over NA: Construction
Compiler->>NA: new NullAway(config, handler, ...)
NA->>NA: defer field init to ctor
NA->>GC: new GenericsChecks(this, config, handler)
NA->>NA: store GC instance
note over NA,GC: Usage during analysis
NA->>GC: checkGenericMethodCallTypeArguments(tree, state)
GC->>GC: internal helpers (uses analysis/config/handler fields)
GC-->>NA: (void)
DF->>GC: getGenericReturnNullnessAtInvocation(symbol, tree, state)
GC-->>DF: Nullness
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ 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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
nullaway/src/main/java/com/uber/nullaway/NullAway.java (1)
301-302: Consider safer initialization pattern for empty constructorWhile the comment acknowledges the issue of leaking
this, consider a safer pattern to avoid potential issues with subclassing or future modifications. You could use a factory method or builder pattern for initialization.public NullAway() { config = new DummyOptionsConfig(); handler = Handlers.buildEmpty(); nonAnnotatedMethod = this::isMethodUnannotated; errorBuilder = new ErrorBuilder(config, "", ImmutableSet.of()); - // annoying to leak `this` here; we assign the field last to make it as safe as possible - genericsChecks = new GenericsChecks(this, config, handler); + // Create genericsChecks in a separate initialization step to avoid leaking this + genericsChecks = createGenericsChecks(); } + +private GenericsChecks createGenericsChecks() { + return new GenericsChecks(this, config, handler); +}
📜 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 (4)
nullaway/src/main/java/com/uber/nullaway/NullAway.java(13 hunks)nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java(1 hunks)nullaway/src/main/java/com/uber/nullaway/generics/CheckIdenticalNullabilityVisitor.java(3 hunks)nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java(51 hunks)
⏰ 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 macos-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.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: Build caffeine with snapshot
- GitHub Check: JDK 11 on ubuntu-latest with Error Prone 2.31.0
- GitHub Check: Build spring-framework with snapshot
🔇 Additional comments (21)
nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java (1)
1105-1106: LGTM!The call to
getGenericReturnNullnessAtInvocationcorrectly uses the updated instance method signature without theConfigparameter, which aligns with the refactoring to makeGenericsChecksstateful.nullaway/src/main/java/com/uber/nullaway/generics/CheckIdenticalNullabilityVisitor.java (3)
17-22: LGTM!The field and constructor changes correctly transition from using
Configto using aGenericsChecksinstance, which is consistent with the refactoring.
65-66: LGTM!The calls to
isNullableAnnotatedcorrectly use the new instance method signature without passingconfig.
96-97: LGTM!The instance method calls are correctly updated here as well, maintaining consistency with the refactoring.
nullaway/src/main/java/com/uber/nullaway/NullAway.java (11)
283-284: Instance field declaration looks goodThe instance field declaration follows Java best practices with the
finalmodifier.
318-319: Initialization order is consistentGood that both constructors follow the same pattern of initializing
genericsCheckslast to minimize the risk of using a partially constructed object.
530-530: Instance method call correctly updatedThe call to
checkTypeParameterNullnessForAssignabilityproperly uses the instance method without redundant parameters.
708-709: Method call signature correctly updatedThe call properly uses the new instance method signature with the overridden method parameter included.
834-839: Instance method calls properly updatedAll generics-related method calls correctly use the instance methods with the simplified signatures.
1003-1008: Generic return type checking correctly updatedThe instance method calls for generic return type nullness checking are properly updated with the new signatures.
1550-1550: Variable initialization checking properly updatedThe call correctly uses the instance method for checking type parameter nullability during variable initialization.
1787-1787: Conditional expression checking correctly updatedThe instance method call for checking type parameter nullability in conditional expressions is properly updated.
1935-1936: Generic parameter nullness checking properly updatedThe instance method call correctly uses the simplified signature without redundant parameters.
1941-1944: Generic method call checking correctly updatedBoth method calls properly use the instance methods with simplified signatures.
2685-2685: Generic return nullness checking properly updatedThe instance method call correctly uses the simplified signature for checking generic return nullness at invocation.
nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java (6)
62-70: LGTM! Well-structured constructorThe constructor properly initializes all instance fields and follows standard Java conventions. The instance-based approach improves encapsulation and reduces method parameter counts throughout the class.
79-80: Simplified method signatures improve API clarityThe removal of
Config,NullAway, andHandlerparameters from public methods significantly simplifies the API surface. All methods now access these dependencies through instance fields, which is a cleaner design.
120-121: Private helper method properly refactoredThe helper method correctly uses instance fields instead of parameters, maintaining consistency with the overall refactoring approach.
587-587: CheckIdenticalNullabilityVisitor instantiation updated correctlyThe visitor is properly instantiated with the
GenericsChecksinstance, allowing it to access the necessary methods without requiring aConfigparameter.
1275-1279: Method signature properly simplifiedThe method correctly uses instance fields for
configandhandler, reducing the parameter count while maintaining the same functionality.
1309-1311: New instance method for nullable annotation checkingGood addition of a public instance method for checking nullable annotations, properly using the instance's
configfield.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1256 +/- ##
============================================
- Coverage 88.50% 88.49% -0.01%
Complexity 2373 2373
============================================
Files 90 90
Lines 7802 7805 +3
Branches 1555 1555
============================================
+ Hits 6905 6907 +2
- Misses 452 453 +1
Partials 445 445 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This helps us delete a ton of individual method parameters and will make other changes in inference easier. This is a pure refactoring PR with no logic changes.
Summary by CodeRabbit