From 79d088e6766296319bb2ac03041b7a809a468a0e Mon Sep 17 00:00:00 2001 From: Mitya Lyubarskiy Date: Fri, 7 Feb 2020 05:11:28 -0800 Subject: [PATCH] [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 --- infer/src/nullsafe/modelTables.ml | 4 ++-- infer/tests/codetoanalyze/java/nullsafe-default/issues.exp | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/infer/src/nullsafe/modelTables.ml b/infer/src/nullsafe/modelTables.ml index e0620eff7..fcda1c5a0 100644 --- a/infer/src/nullsafe/modelTables.ml +++ b/infer/src/nullsafe/modelTables.ml @@ -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" ) diff --git a/infer/tests/codetoanalyze/java/nullsafe-default/issues.exp b/infer/tests/codetoanalyze/java/nullsafe-default/issues.exp index b7bd7ee3c..7aacbe5ab 100644 --- a/infer/tests/codetoanalyze/java/nullsafe-default/issues.exp +++ b/infer/tests/codetoanalyze/java/nullsafe-default/issues.exp @@ -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()`.]