uber / NullAway

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

JSpecify: Handle @Nullable elements for enhanced-for-loops on arrays #986

Closed armughan11 closed 2 months ago

armughan11 commented 2 months ago

Currently, enhanced-for-loops do not honor nullability annotations on arrays.

Current Behavior Both these dereferences work fine.

static @Nullable String[] fizz = {"1"}
for (String s: fizz){
     s.toString();
     if (s!=null){
          s.toString();
     }  
}

New Behavior The first one throws an error, as expected.

static @Nullable String[] fizz = {"1"}
for (String s: fizz){
     // BUG: Diagnostic contains: dereferenced expression s is @Nullable
     s.toString();
     if (s!=null){
          s.toString();
     }  
}

Fixes #983

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 85.95%. Comparing base (cc3dee3) to head (da98d36).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #986 +/- ## ========================================= Coverage 85.94% 85.95% - Complexity 2069 2070 +1 ========================================= Files 83 83 Lines 6860 6863 +3 Branches 1318 1319 +1 ========================================= + Hits 5896 5899 +3 Misses 550 550 Partials 414 414 ```

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