[nullsafe][EASY] functions that are modelled as @TrueOnNull should be also modelled for nullability.

Summary:
If we managed to whitelist a function as TrueOnNull, we should teach
nullsafe the nullability of its arguments, otherwise it will ask not to
pass null here.

This fixes a silly FP warning, see the test.

Reviewed By: dulmarod

Differential Revision: D19770341

fbshipit-source-id: 0f861fae1
master
Mitya Lyubarskiy 5 years ago committed by Facebook Github Bot
parent 067a545c0e
commit 79d088e676

@ -205,7 +205,7 @@ let check_argument_list =
(** Models for boolean functions that return true on null. *)
let true_on_null_list : ((_ * bool list) * _) list =
let true_on_null_list =
[ (n1, "android.text.TextUtils.isEmpty(java.lang.CharSequence):boolean")
; (n1, "com.google.common.base.Strings.isNullOrEmpty(java.lang.String):boolean") ]
@ -226,7 +226,7 @@ let mapPut_list =
(** Models for nullability *)
let annotated_list_nullability =
check_not_null_list @ check_state_list @ check_argument_list
check_not_null_list @ check_state_list @ check_argument_list @ true_on_null_list
@ [ ( o1
, "android.text.SpannableString.valueOf(java.lang.CharSequence):android.text.SpannableString"
)

@ -248,7 +248,6 @@ codetoanalyze/java/nullsafe-default/SwitchCase.java, codetoanalyze.java.nullsafe
codetoanalyze/java/nullsafe-default/SwitchCase.java, codetoanalyze.java.nullsafe_default.SwitchCase.switchOnNullIsBad():java.lang.String, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [NullPointerException will be thrown at this line! `color` is `null` and is dereferenced via calling `ordinal()`: null constant at line 14]
codetoanalyze/java/nullsafe-default/SwitchCase.java, codetoanalyze.java.nullsafe_default.SwitchCase.switchOnNullableIsBad():java.lang.String, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`color` is nullable and is not locally checked for null when calling `ordinal()`: call to getNullableColor() at line 28]
codetoanalyze/java/nullsafe-default/TrueFalseOnNull.java, codetoanalyze.java.nullsafe_default.TrueFalseOnNull$EarlyReturn.testEarlyReturn(java.lang.CharSequence,java.lang.CharSequence):void, 5, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`s2` is nullable and is not locally checked for null when calling `toString()`.]
codetoanalyze/java/nullsafe-default/TrueFalseOnNull.java, codetoanalyze.java.nullsafe_default.TrueFalseOnNull$TestModels.testModelledTrueOnNull(java.lang.String):void, 0, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [`TextUtils.isEmpty(...)`: parameter #1 is declared non-nullable but the argument `s` is nullable.]
codetoanalyze/java/nullsafe-default/TrueFalseOnNull.java, codetoanalyze.java.nullsafe_default.TrueFalseOnNull$TestNonStaticOneParam.falseOnNullNegativeBranchIsBAD(java.lang.String):void, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`s` is nullable and is not locally checked for null when calling `toString()`.]
codetoanalyze/java/nullsafe-default/TrueFalseOnNull.java, codetoanalyze.java.nullsafe_default.TrueFalseOnNull$TestNonStaticOneParam.notAnnotatedNegativeBranchIsBAD(java.lang.String):void, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`s` is nullable and is not locally checked for null when calling `toString()`.]
codetoanalyze/java/nullsafe-default/TrueFalseOnNull.java, codetoanalyze.java.nullsafe_default.TrueFalseOnNull$TestNonStaticOneParam.notAnnotatedPositiveBranchIsBAD(java.lang.String):void, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`s` is nullable and is not locally checked for null when calling `toString()`.]

Loading…
Cancel
Save