uber / NullAway

A tool to help eliminate NullPointerExceptions (NPEs) in your Java code with low build-time overhead
MIT License
3.63k stars 293 forks source link

External Library Models: Adding support for Nullable upper bounds of Generic Type parameters #949

Closed akulk022 closed 4 months ago

akulk022 commented 6 months ago

With these changes we are able to read and create library models for Nullable upper bounds of generic type parameters from externally annotated source code as shown in the below example.

Externally annotated source code example:

public static class GenericExample<T extends @Nullable Object> {
        public T getNull() {
            return null;
        }
 }
public static class GenericExample<T> {
    public T getNull() {
      return null;
    }
}
static GenericExample<@Nullable Object> genericExample = new GenericExample<@Nullable Object>();
static void test(Object value){}
// BUG: Diagnostic contains: passing @Nullable parameter 'genericExample.getNull()'
test(genericExample.getNull());
codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 66.90647% with 46 lines in your changes missing coverage. Please review.

Project coverage is 85.97%. Comparing base (6cec433) to head (71ce2e2).

:exclamation: Current head 71ce2e2 differs from pull request most recent head 3f4c3e4

Please upload reports for the commit 3f4c3e4 to get more accurate results.

Files Patch % Lines
.../uber/nullaway/libmodel/LibraryModelGenerator.java 0.00% 23 Missing :warning:
...ava/com/uber/nullaway/handlers/StubxCacheUtil.java 81.33% 9 Missing and 5 partials :warning:
...n/java/com/uber/nullaway/libmodel/StubxWriter.java 27.27% 7 Missing and 1 partial :warning:
...er/nullaway/handlers/InferredJARModelsHandler.java 75.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #949 +/- ## ============================================ - Coverage 86.17% 85.97% -0.20% - Complexity 2037 2046 +9 ============================================ Files 81 82 +1 Lines 6691 6760 +69 Branches 1290 1301 +11 ============================================ + Hits 5766 5812 +46 - Misses 515 536 +21 - Partials 410 412 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.