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

Fix handling of references to methods of array types and type variables #926

Merged
merged 3 commits into from
Mar 4, 2024

Conversation

msridhar
Copy link
Collaborator

@msridhar msridhar commented Mar 3, 2024

After #920 we check the nullability of the qualifier expression of a method reference. We weren't correctly handling the cases where that expression was an array type or a type variable

@msridhar msridhar requested a review from yuxincs March 3, 2024 17:26
@msridhar msridhar enabled auto-merge (squash) March 3, 2024 17:26
Copy link

codecov bot commented Mar 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.09%. Comparing base (a42b3a8) to head (d095f4f).
Report is 1 commits behind head on master.

❗ Current head d095f4f differs from pull request most recent head 2a0a3fb. Consider uploading reports for the commit 2a0a3fb to get more accurate results

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #926   +/-   ##
=========================================
  Coverage     87.09%   87.09%           
- Complexity     1991     1992    +1     
=========================================
  Files            77       77           
  Lines          6430     6431    +1     
  Branches       1245     1246    +1     
=========================================
+ Hits           5600     5601    +1     
  Misses          422      422           
  Partials        408      408           

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

@msridhar msridhar disabled auto-merge March 3, 2024 22:51
@msridhar msridhar marked this pull request as draft March 3, 2024 22:51
@msridhar msridhar changed the title Fix crash when qualifier expression of method reference is an array type Fix handling of references to methods of array types and type variables Mar 3, 2024
@msridhar msridhar marked this pull request as ready for review March 3, 2024 23:11
@@ -2326,7 +2326,7 @@ private boolean mayBeNullExpr(VisitorState state, ExpressionTree expr) {
return true;
case NEW_CLASS:
case NEW_ARRAY:
// for string concatenation, auto-boxing
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was an outdated comment so I deleted it

Comment on lines +2488 to +2489
|| ElementUtils.isTypeElement(baseExpressionSymbol)
|| baseExpressionSymbol.getKind() == ElementKind.TYPE_PARAMETER) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to suggest to me that we were handling cases where the expression is an array type (presumably isTypeElement check), but not the case for type parameters (the second negative test added in this PR). Right?

Makes sense to me either way, but just want to understand this better :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not quite. The isTypeElement method only catches when the element is a class, enum, interface, or annotation type; array types are not handled. That case is handled by the line this PR adds to mayBeNullExpr.

For type variables, the expression itself is just an IdentifierTree. We know it can't be null because it represents a type parameter; that is caught by the check on this line.

Copy link
Collaborator

@yuxincs yuxincs left a comment

Choose a reason for hiding this comment

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

Makes sense to me! :)

@msridhar msridhar merged commit 348bb4d into uber:master Mar 4, 2024
10 checks passed
@msridhar msridhar deleted the method-ref-to-array-type branch March 4, 2024 17:09
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