Skip to content
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

JSpecify: Handle @Nullable assignments to @Nonnull arrays #929

Merged
merged 5 commits into from
Mar 11, 2024

Conversation

armughan11
Copy link
Collaborator

@armughan11 armughan11 commented Mar 10, 2024

Handles cases in JSpecify mode where a @Nullable element is assigned to an unannotated array. Added relevant unit tests.

Current Behavior

Both are valid assignments.

String [] foo = new String[10];
@Nullable String [] bar = new String [10];
foo[1] = null;
bar[1] = null;

New Behavior

Assignment to foo generates an error since array elements are @Nonnull.

String [] foo = new String[10];
@Nullable String [] bar = new String [10];
foo[1] = null;
bar[1]=null;

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

Awesome! I have a couple of comments but this looks great

Comment on lines 509 to 510
String message = "assigning @Nullable expression to @NonNull field.";
return buildDescription(tree).setMessage(message).build();
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need a more appropriate message here, like "Writing @Nullable expression into array with @NonNull contents". Also you should use the ErrorBuilder APIs and add a new ErrorMessage message type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed!

Co-authored-by: Manu Sridharan <msridhar@gmail.com>
Copy link

codecov bot commented Mar 10, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 87.07%. Comparing base (1c497a7) to head (bdb8f10).

Files Patch % Lines
...away/src/main/java/com/uber/nullaway/NullAway.java 84.61% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #929      +/-   ##
============================================
- Coverage     87.07%   87.07%   -0.01%     
- Complexity     1991     1994       +3     
============================================
  Files            77       77              
  Lines          6430     6444      +14     
  Branches       1246     1249       +3     
============================================
+ Hits           5599     5611      +12     
  Misses          422      422              
- Partials        409      411       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

Looking great! Just a couple more things

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution!

@msridhar msridhar merged commit e3a3c76 into uber:master Mar 11, 2024
10 of 12 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.

None yet

2 participants