You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following code using a record pattern:
classRecords {
record Rec(Objectfst, @NullableObjectsnd) {}
voidex(Objectobj) {
if (objinstanceofRec(Objectf, @NullableObjects)) {
s.toString(); // possible NPE
}
}
}
It seems clear NullAway should report an error on the dereference above. What if the code is written as follows?
voidex(Objectobj) {
if (objinstanceofRec(Objectf, Objects)) {
s.toString(); // possible NPE
}
}
Here I think the error should be reported in the pattern itself: if the code explicitly writes Object s, the top-level nullability annotation should match the record declaration. Finally, if var is used:
voidex(Objectobj) {
if (objinstanceofRec(varf, vars)) {
s.toString(); // possible NPE
}
}
Here I think we should infer the type of s to be @Nullable Object. I think all of the above also holds for uses of record patterns in switch cases.
The text was updated successfully, but these errors were encountered:
Consider the following code using a record pattern:
It seems clear NullAway should report an error on the dereference above. What if the code is written as follows?
Here I think the error should be reported in the pattern itself: if the code explicitly writes
Object s
, the top-level nullability annotation should match the record declaration. Finally, ifvar
is used:Here I think we should infer the type of
s
to be@Nullable Object
. I think all of the above also holds for uses of record patterns in switch cases.The text was updated successfully, but these errors were encountered: