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

JSpecify: handling the return of a diamond operator anonymous object method caller #858

Merged

Conversation

akulk022
Copy link
Collaborator

@akulk022 akulk022 commented Nov 10, 2023

In reference to the exception mentioned in the discussion for #791 .

Adding the test case to reproduce the same issue:

class Test {
    static class B<T>{
        String build(){return "x";}
    }
    static String testNegative() {
        //We were getting the aforementioned mentioned exception when we tried to do this
        return new B<>().build();
    }
}

All unit tests have passed for the changes that were made for this.

Copy link

codecov bot commented Nov 10, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0141aca) 86.93% compared to head (35c0cc3) 86.95%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #858      +/-   ##
============================================
+ Coverage     86.93%   86.95%   +0.01%     
- Complexity     1888     1890       +2     
============================================
  Files            74       74              
  Lines          6215     6216       +1     
  Branches       1208     1209       +1     
============================================
+ Hits           5403     5405       +2     
  Misses          405      405              
+ Partials        407      406       -1     
Files Coverage Δ
...rc/main/java/com/uber/nullaway/GenericsChecks.java 90.31% <100.00%> (+0.02%) ⬆️

... and 1 file with indirect coverage changes

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

// TODO: support diamond operators
return Nullness.NONNULL;
}
}
Type methodReceiverType =
castToNonNull(
getTreeType(((MemberSelectTree) tree.getMethodSelect()).getExpression(), state));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of adding all the code above, why not just store the result of this getTreeType() call in a local variable, and if it is null, return Nullness.NONNULL? That is more general I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, I added it in the same condition, does this work?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to do it after that condition and store the result of getTreeType() in a local variable, so we don't call it twice. Otherwise the logic looks good.

@msridhar msridhar marked this pull request as ready for review November 13, 2023 18:25
@msridhar msridhar enabled auto-merge (squash) November 13, 2023 18:25
@msridhar msridhar merged commit 4af912d into uber:master Nov 13, 2023
10 checks passed
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.

2 participants