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: handle return types of method references in Java Generics #847

Merged

Conversation

akulk022
Copy link
Collaborator

@akulk022 akulk022 commented Oct 15, 2023

Adding new test case and the logic to handle the negative scenario of the test case where we were getting a false positive earlier.

class Test {
    interface A<T1 extends @Nullable Object> {
        T1 function(Object o);
    }
    static @Nullable String foo(Object o) {
        return o.toString();
    }
    static void testPositive() {
    // BUG: Diagnostic contains: referenced method returns @Nullable
	A<String> p = Test::foo;
    }
    static void testNegative() {
    // We were getting a false positive error on this line as the Nullability of the overriden method was not identified
        A<@Nullable String> p = Test::foo;
    }
}

All test cases in NullAwayJSpecifyGenericTests.java passed for these changes.

@akulk022 akulk022 changed the title Logic to handle return types of method references in Java Generics JSPecify: logic to handle return types of method references in Java Generics Oct 15, 2023
@akulk022 akulk022 changed the title JSPecify: logic to handle return types of method references in Java Generics JSpecify: logic to handle return types of method references in Java Generics Oct 15, 2023
@akulk022 akulk022 changed the title JSpecify: logic to handle return types of method references in Java Generics JSpecify: handle return types of method references in Java Generics Oct 15, 2023
@codecov
Copy link

codecov bot commented Oct 15, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (099a7a5) 86.86% compared to head (56f95e3) 86.87%.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #847   +/-   ##
=========================================
  Coverage     86.86%   86.87%           
- Complexity     1879     1880    +1     
=========================================
  Files            74       74           
  Lines          6196     6200    +4     
  Branches       1202     1202           
=========================================
+ Hits           5382     5386    +4     
  Misses          406      406           
  Partials        408      408           
Files Coverage Δ
...rc/main/java/com/uber/nullaway/GenericsChecks.java 90.28% <100.00%> (ø)
...away/src/main/java/com/uber/nullaway/NullAway.java 89.77% <100.00%> (+0.03%) ⬆️

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

@msridhar msridhar added the jspecify Related to support for jspecify standard (see jspecify.dev) label Oct 15, 2023
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.

Great start! Couple comments

nullaway/src/main/java/com/uber/nullaway/NullAway.java Outdated Show resolved Hide resolved
@@ -439,6 +439,31 @@ public void testForMethodReferenceInAnAssignment() {
.doTest();
}

@Test
public void testForMethodReferenceReturnType() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As noted in an offline discussion, this test looks good but let's add tests for more (pseudo-)assignments, like passing a method reference as a function parameter and returning a method reference

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.

LGTM!

@msridhar msridhar marked this pull request as ready for review October 19, 2023 16:59
@msridhar msridhar enabled auto-merge (squash) October 19, 2023 16:59
@msridhar msridhar merged commit 8f270e2 into uber:master Oct 19, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jspecify Related to support for jspecify standard (see jspecify.dev)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants