Skip to content

Add more instance fields to GenericsChecks#1256

Merged
msridhar merged 4 commits intomasterfrom
more-instance-state-in-generics-checks
Aug 24, 2025
Merged

Add more instance fields to GenericsChecks#1256
msridhar merged 4 commits intomasterfrom
more-instance-state-in-generics-checks

Conversation

@msridhar
Copy link
Copy Markdown
Collaborator

@msridhar msridhar commented Aug 24, 2025

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

  • Refactor
    • Streamlined generics-related nullability checks by moving to instance-based logic initialized via constructors.
    • Reduced parameter passing and centralized configuration/handler usage for improved encapsulation and maintainability.
    • Converted previous static-style calls to instance methods without altering user-facing behavior.
    • Preserved public API surface; no changes required for integrators.
  • Chores
    • Added internal comments clarifying initialization order to prevent construction-time issues.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 24, 2025

Walkthrough

Refactors 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

Cohort / File(s) Summary
Core analysis wiring
nullaway/src/main/java/com/uber/nullaway/NullAway.java
Moves GenericsChecks initialization from field inline to constructors; introduces new GenericsChecks(this, config, handler); replaces previous static-like calls with instance calls; removes passing this/config/handler to these methods.
Generics checks refactor
nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java
Converts many static methods to instance methods; adds fields for analysis, config, handler; adds constructor; removes config/analysis/handler parameters from numerous APIs; consolidates helpers to use internal state; updates signatures for get/check methods (parameters reduced).
Visitors adjustment
nullaway/src/main/java/com/uber/nullaway/generics/CheckIdenticalNullabilityVisitor.java
Replaces Config dependency with GenericsChecks; updates constructor to accept GenericsChecks; switches GenericsChecks.isNullableAnnotated(..., config) to instance genericsChecks.isNullableAnnotated(...).
Dataflow propagation
nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java
Updates call to getGenericReturnNullnessAtInvocation to new signature (drops config parameter); logic unchanged otherwise.

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
Loading

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch more-instance-state-in-generics-checks

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 @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai 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:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai 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 @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @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.

@msridhar msridhar enabled auto-merge (squash) August 24, 2025 00:27
Copy link
Copy Markdown
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 (1)
nullaway/src/main/java/com/uber/nullaway/NullAway.java (1)

301-302: Consider safer initialization pattern for empty constructor

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

📥 Commits

Reviewing files that changed from the base of the PR and between 044418a and d8069af.

📒 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 getGenericReturnNullnessAtInvocation correctly uses the updated instance method signature without the Config parameter, which aligns with the refactoring to make GenericsChecks stateful.

nullaway/src/main/java/com/uber/nullaway/generics/CheckIdenticalNullabilityVisitor.java (3)

17-22: LGTM!

The field and constructor changes correctly transition from using Config to using a GenericsChecks instance, which is consistent with the refactoring.


65-66: LGTM!

The calls to isNullableAnnotated correctly use the new instance method signature without passing config.


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 good

The instance field declaration follows Java best practices with the final modifier.


318-319: Initialization order is consistent

Good that both constructors follow the same pattern of initializing genericsChecks last to minimize the risk of using a partially constructed object.


530-530: Instance method call correctly updated

The call to checkTypeParameterNullnessForAssignability properly uses the instance method without redundant parameters.


708-709: Method call signature correctly updated

The call properly uses the new instance method signature with the overridden method parameter included.


834-839: Instance method calls properly updated

All generics-related method calls correctly use the instance methods with the simplified signatures.


1003-1008: Generic return type checking correctly updated

The instance method calls for generic return type nullness checking are properly updated with the new signatures.


1550-1550: Variable initialization checking properly updated

The call correctly uses the instance method for checking type parameter nullability during variable initialization.


1787-1787: Conditional expression checking correctly updated

The instance method call for checking type parameter nullability in conditional expressions is properly updated.


1935-1936: Generic parameter nullness checking properly updated

The instance method call correctly uses the simplified signature without redundant parameters.


1941-1944: Generic method call checking correctly updated

Both method calls properly use the instance methods with simplified signatures.


2685-2685: Generic return nullness checking properly updated

The 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 constructor

The 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 clarity

The removal of Config, NullAway, and Handler parameters 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 refactored

The helper method correctly uses instance fields instead of parameters, maintaining consistency with the overall refactoring approach.


587-587: CheckIdenticalNullabilityVisitor instantiation updated correctly

The visitor is properly instantiated with the GenericsChecks instance, allowing it to access the necessary methods without requiring a Config parameter.


1275-1279: Method signature properly simplified

The method correctly uses instance fields for config and handler, reducing the parameter count while maintaining the same functionality.


1309-1311: New instance method for nullable annotation checking

Good addition of a public instance method for checking nullable annotations, properly using the instance's config field.

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 24, 2025

Codecov Report

❌ Patch coverage is 98.91304% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.49%. Comparing base (044418a) to head (d8069af).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...away/src/main/java/com/uber/nullaway/NullAway.java 95.65% 1 Missing ⚠️
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.
📢 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 f7e8def into master Aug 24, 2025
14 checks passed
@msridhar msridhar deleted the more-instance-state-in-generics-checks branch August 24, 2025 15:02
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