Closed armughan11 closed 2 months ago
@msridhar
Attention: Patch coverage is 86.25000%
with 11 lines
in your changes missing coverage. Please review.
Project coverage is 85.90%. Comparing base (
a4ce249
) to head (5df5697
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
We should add tests for the following cases:
m()[i]
)m[i()]
)if (m[i] != null) { m[i+1].hashCode(); }
should yield an error)您好,邮件已经收到,查阅后会尽快给您回复!
I realized this change might have a deeper impact than we were expecting. Right now, the creation of access path elements for array accesses is not gated on the flag for JSpecify mode, and passing the NullAway config into all relevant methods to do that would be kind of painful. But, I believe this means that code like this will pass NullAway now, when it didn't before this change:
if (arr[i].f != null) {
arr[i].f.toString();
}
@armughan11 can you write a test to confirm this?
@lazaroclapp do you see any high-level issues with not reporting warnings for code like the above? It seems to be keeping in the spirit of NullAway, but it does potentially introduce new vectors of unsoundness, e.g.:
if (arr[i].f != null) {
arr[j] = null; // overwrites a[i] if i == j
arr[i].f.toString(); // still no warning from NullAway
}
Most programs don't code too much directly with arrays, but I wonder if we should do some more performance and sanity testing before landing this.
Just added the test and you're correct @msridhar. The test you mentioned works fine right now, but throws an error without our changes.
Gonna go ahead and merge this; I think we can address any concerns in follow-up PRs
Handles unexpected error cases in JSpecify mode where an index is asserted
@Nonnull
(fizz[x]!=null
) but the array elements itself could be null (@Nullable String [] fizz
).Example
Current Behavior This throws an error due to dereference of
fizz[i]
New Behavior There should be no error here unless it's outside the block. So only the latter dereference throws up an error in the below case.