-
Notifications
You must be signed in to change notification settings - Fork 288
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
Restrictive annotated method overriding #249
Restrictive annotated method overriding #249
Conversation
…ck method overriding
…ck method overriding
…:shas19/NullAway into restrictive_annotated_method_overridding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments and nits, but I'd be fine with merging this pretty much as it is. Thanks! 👍
NullAway analysis, | ||
VisitorState state, | ||
Symbol.MethodSymbol methodSymbol, | ||
ImmutableSet<Integer> explicitlyNullablePositions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This is piggybacking on the logic for the LibraryModelsHandler
which does handle overriding, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Also is it possible that in future we might want to handle nullness of return values in LibraryModelsHandler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean for overriding? The case of handling use of null return values from library models is done by onOverrideMayBeNullExpr
.
It might be worth adding onUnannotatedInvocationGetExplicitlyNonNullReturn
to that handler as well, though, want to do it as another short PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'll go for another short PR
// @NonNull return | ||
// values if needed. | ||
final boolean isOverridenMethodUnannotated = | ||
NullabilityUtil.isUnannotated(overriddenMethod, config); | ||
boolean overriddenMethodReturnsNonNull = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I like your final
above, can we make this final
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
"-XepOpt:NullAway:UnannotatedSubPackages=com.uber.lib.unannotated", | ||
"-XepOpt:NullAway:AcknowledgeRestrictiveAnnotations=true")) | ||
.addSourceLines( | ||
"Test.java", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Rename this to TestNegativeCases.java
and the class accordingly. Would make the test easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
" @Override public @Nullable Object returnsNullable2() { return new Object();}", | ||
"}") | ||
.addSourceLines( | ||
"Test2.java", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestPositiveCases.java
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Following changes are addressed,
If the restrictive annotations are turned on then
@Nullable
return and the third-party method is restrictively annotated as@NonNull
then triggers an error.@Nullable
but the same position argument to the overridden third-party method is restrictively annotated as@Nullable
then also triggers an error.Fixes #236
Added unit tests.