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

Adding support for nullable type upper bounds considering Library models #903

Closed akulk022 closed 8 months ago

akulk022 commented 8 months ago

The below line previously reported an error considering the upperbound of the generic type parameter couldn't be Nullable, adding it into library models to allow it to be Nullable passes the test case.

Function<String,@Nullable String> removeA = a -> a.replace("a","");

We now have library model methods for treating a type as @NullMarked and also for making the upper bound of type variables @Nullable. We use these new methods to model java.util.function.Function as @NullMarked, in JSpecify mode only.

We fixed a related issue with unwanted errors when passing a lambda / method reference to @NullUnmarked code; this was necessary to get NullAway itself to still build with NullAway checking enabled.

(Due to issues with the branch this PR was recreated from the original #893)

codecov[bot] commented 8 months ago

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (3fc9b8a) 86.98% compared to head (d55b045) 87.05%. Report is 3 commits behind head on master.

Files Patch % Lines
...c/main/java/com/uber/nullaway/NullabilityUtil.java 66.66% 1 Missing and 2 partials :warning:
...away/src/main/java/com/uber/nullaway/NullAway.java 93.75% 0 Missing and 2 partials :warning:
...ava/com/uber/nullaway/generics/GenericsChecks.java 88.88% 0 Missing and 2 partials :warning:
...src/main/java/com/uber/nullaway/LibraryModels.java 66.66% 1 Missing :warning:
...llaway/dataflow/AccessPathNullnessPropagation.java 85.71% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #903 +/- ## ============================================ + Coverage 86.98% 87.05% +0.07% - Complexity 1959 1988 +29 ============================================ Files 77 77 Lines 6330 6414 +84 Branches 1223 1245 +22 ============================================ + Hits 5506 5584 +78 - Misses 420 422 +2 - Partials 404 408 +4 ```

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

msridhar commented 8 months ago

Going ahead and merging this one. Thanks again @akulk022!