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

Restrictive annotated method overriding #249

Merged

Conversation

shubhamugare
Copy link
Contributor

Following changes are addressed,
If the restrictive annotations are turned on then

  1. If the first-party overriding method has a marked @Nullable return and the third-party method is restrictively annotated as @NonNull then triggers an error.
  2. If an argument to the first-party overriding method is not marked @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.

Copy link
Collaborator

@lazaroclapp lazaroclapp left a 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) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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?

Copy link
Collaborator

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?

Copy link
Contributor Author

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 =
Copy link
Collaborator

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?

Copy link
Contributor Author

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",
Copy link
Collaborator

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.

Copy link
Contributor Author

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",
Copy link
Collaborator

Choose a reason for hiding this comment

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

TestPositiveCases.java?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@lazaroclapp lazaroclapp merged commit d1684d9 into uber:master Oct 24, 2018
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