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

Refactor simple onOverrideMayBeNullExpr handlers #747

Merged
merged 2 commits into from Mar 30, 2023

Conversation

XN137
Copy link
Contributor

@XN137 XN137 commented Mar 12, 2023

execution of the affected handlers is inconsequential when parameter exprMayBeNull is already true

execution of the touched handler methods is inconsequential
when parameter exprMayBeNull is already true
Copy link
Contributor Author

@XN137 XN137 left a comment

Choose a reason for hiding this comment

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

a similar refactoring is possible for LibraryModelsHandler but i wanted to "test out the water" first 😅

&& exprSymbol instanceof Symbol.MethodSymbol) {
return exprMayBeNull || isReturnAnnotatedNullable((Symbol.MethodSymbol) exprSymbol);
if (exprMayBeNull) {
return true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

like a preamble: "this handler only supports false -> true transitions"

&& isReturnAnnotatedNullable((Symbol.MethodSymbol) exprSymbol)) {
return true;
}
return false;
Copy link
Contributor Author

@XN137 XN137 Mar 12, 2023

Choose a reason for hiding this comment

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

this is structured like:

if reason1_why_expr_may_be_null:
  return true
if reason2_why_expr_may_be_null:
  return true
return false

when there is only a single reason, we could of course use the condition in a single return statement if preferred?

the old style is imo more confusing (an has redundant checks):

if check1:
  return exprMayBeNull || check2
return exprMayBeNull

if any of the checks have important side-effects (that i am not seeing) we should add tests that expose those imo.

Copy link
Collaborator

Choose a reason for hiding this comment

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

agreed this is an improvement here

if (exprMayBeNull) {
return true;
}
if (expr.getKind() == Tree.Kind.METHOD_INVOCATION
&& exprSymbol instanceof Symbol.MethodSymbol
&& optionalIsGetCall((Symbol.MethodSymbol) exprSymbol, state.getTypes())) {
return true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the old code, this line returning true (and thus the whole if condition) only matters, if we wouldnt eventually be returning true with return exprMayBeNull anyway.

this again is assuming that the checks have no side-effects (if they do tests around it are missing)

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.

These changes LGTM. Sorry for the slow review. I will rewrite the PR title a bit and then merge

&& isReturnAnnotatedNullable((Symbol.MethodSymbol) exprSymbol)) {
return true;
}
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

agreed this is an improvement here

@msridhar msridhar changed the title refactor simple onOverrideMayBeNullExpr handlers Refactor simple onOverrideMayBeNullExpr handlers Mar 30, 2023
@msridhar msridhar enabled auto-merge (squash) March 30, 2023 16:39
@msridhar msridhar merged commit 7714c45 into uber:master Mar 30, 2023
7 checks passed
@XN137 XN137 deleted the refactor-simple-handlers branch March 31, 2023 08:05
msridhar added a commit to msridhar/NullAway that referenced this pull request Jul 18, 2023
msridhar added a commit to msridhar/NullAway that referenced this pull request Jul 18, 2023
msridhar added a commit to msridhar/NullAway that referenced this pull request Jul 19, 2023
msridhar added a commit to msridhar/NullAway that referenced this pull request Jul 19, 2023
msridhar added a commit to msridhar/NullAway that referenced this pull request Jul 19, 2023
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