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

Enforce correct type-use annotation locations for nested types #1045

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

armughan11
Copy link
Collaborator

Enforce correct type-use annotation locations for nested types as per JSpecify norms. We enforce type-use annotations to be on the inner class and raise an error if they are not. For annotations that are both type use and declaration, we raise an error at an invalid location.

Current behavior

// All three are ok

@Nullable A.B.C foo1 = null;
A.@Nullable B.C foo2 = null;
A.B.@Nullable C foo3 = null;

New behavior

// BUG: Diagnostic contains: Type-use nullability annotations should be applied on inner class
@Nullable A.B.C foo1 = null;
// BUG: Diagnostic contains: Type-use nullability annotations should be applied on inner class
A.@Nullable B.C foo2 = null;
A.B.@Nullable C foo3 = null;


For annotations which are both declaration and annotation and type-use, only foo2 throws an error since the location isn't apt for either scenarios

Copy link

codecov bot commented Sep 25, 2024

Codecov Report

Attention: Patch coverage is 90.62500% with 3 lines in your changes missing coverage. Please review.

Project coverage is 87.56%. Comparing base (940c40e) to head (61b0cdc).

Files with missing lines Patch % Lines
...away/src/main/java/com/uber/nullaway/NullAway.java 81.81% 1 Missing and 1 partial ⚠️
...c/main/java/com/uber/nullaway/NullabilityUtil.java 95.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1045      +/-   ##
============================================
+ Coverage     87.54%   87.56%   +0.01%     
- Complexity     2138     2155      +17     
============================================
  Files            83       83              
  Lines          7003     7030      +27     
  Branches       1367     1376       +9     
============================================
+ Hits           6131     6156      +25     
- Misses          451      452       +1     
- Partials        421      422       +1     

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

@msridhar msridhar linked an issue Sep 26, 2024 that may be closed by this pull request
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.

This is a great start! I think we are missing checking on various occurrences of annotated types, like method return types. We should be doing checking in all the places that this checker does it. Can we add that, and also tests?

Comment on lines +1480 to +1484
if (hasNestedClass(state.getTypes(), symbol.type)) {
errorMessage =
new ErrorMessage(
MessageTypes.NULLABLE_ON_WRONG_NESTED_CLASS_LEVEL,
"Type-use nullability annotations should be applied on inner class");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't understand this check and why it occurs here? I think the check should occur independent of whether the initializer assignment is valid. If we need to possibly report multiple error messages from this method, we can use the state.reportMatch API to report the errors and then just always return Description.NO_MATCH.

Comment on lines +1501 to +1503
if (types == null || type == null) {
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.

If these null checks are necessary the parameters should be @Nullable. But I don't think they are needed?

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.

Enforce correct type-use annotation locations for nested types
2 participants