diff --git a/infer/src/eradicate/modelTables.ml b/infer/src/eradicate/modelTables.ml index c7dca3642..f049b7ffd 100644 --- a/infer/src/eradicate/modelTables.ml +++ b/infer/src/eradicate/modelTables.ml @@ -158,7 +158,8 @@ let optional_isPresent_list : ((_ * bool list) * _) list = (** Models for boolean functions that return true on null. *) let true_on_null_list : ((_ * bool list) * _) list = - [(n1, "android.text.TextUtils.isEmpty(java.lang.CharSequence):boolean")] + [ (n1, "android.text.TextUtils.isEmpty(java.lang.CharSequence):boolean") + ; (n1, "com.google.common.base.Strings.isNullOrEmpty(java.lang.String):boolean") ] (** Models for Map.containsKey *) diff --git a/infer/tests/codetoanalyze/java/eradicate/CustomAnnotations.java b/infer/tests/codetoanalyze/java/eradicate/CustomAnnotations.java index 681f103bf..0f9874d67 100644 --- a/infer/tests/codetoanalyze/java/eradicate/CustomAnnotations.java +++ b/infer/tests/codetoanalyze/java/eradicate/CustomAnnotations.java @@ -16,7 +16,7 @@ import com.facebook.infer.annotation.Assertions; import com.facebook.infer.annotation.FalseOnNull; import com.facebook.infer.annotation.PropagatesNullable; import com.facebook.infer.annotation.TrueOnNull; - +import com.google.common.base.Strings; public class CustomAnnotations { @@ -70,7 +70,6 @@ public class CustomAnnotations { } } - // Tests for the annotation @PropagatesNullable class TestPropagatesNullable { @@ -126,4 +125,19 @@ public class CustomAnnotations { m12("", "").length(); } } + + class TestModeledTrueOnNull { + + void testIsEmptyOrNullOk(@Nullable String string) { + if (!Strings.isNullOrEmpty(string)) { + string.contains("Infer"); + } + } + + void testIsEmptyOrNullBad(@Nullable String string) { + if (Strings.isNullOrEmpty(string)) { + string.contains("Infer"); + } + } + } } diff --git a/infer/tests/codetoanalyze/java/eradicate/issues.exp b/infer/tests/codetoanalyze/java/eradicate/issues.exp index 75795e39d..bc6c619e5 100644 --- a/infer/tests/codetoanalyze/java/eradicate/issues.exp +++ b/infer/tests/codetoanalyze/java/eradicate/issues.exp @@ -1,8 +1,9 @@ codetoanalyze/java/eradicate/ActivityFieldNotInitialized.java, ActivityFieldNotInitialized$BadActivityWithOnCreate.(ActivityFieldNotInitialized), 0, ERADICATE_FIELD_NOT_INITIALIZED, ERROR, [Field `ActivityFieldNotInitialized$BadActivityWithOnCreate.field` is not initialized in the constructor and is not declared `@Nullable`] -codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestPropagatesNullable.m12Bad1(), 1, ERADICATE_NULL_METHOD_CALL, ERROR, [origin,The value of `m12(...)` in the call to `length()` could be null. (Origin: call to m12(...) at line 118)] -codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestPropagatesNullable.m12Bad2(), 1, ERADICATE_NULL_METHOD_CALL, ERROR, [origin,The value of `m12(...)` in the call to `length()` could be null. (Origin: call to m12(...) at line 122)] -codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestPropagatesNullable.m2Bad(), 1, ERADICATE_NULL_METHOD_CALL, ERROR, [origin,The value of `m2(...)` in the call to `length()` could be null. (Origin: call to m2(...) at line 105)] -codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestPropagatesNullable.mBad(), 1, ERADICATE_NULL_METHOD_CALL, ERROR, [origin,The value of `m(...)` in the call to `length()` could be null. (Origin: call to m(...) at line 83)] +codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestModeledTrueOnNull.testIsEmptyOrNullBad(String), 2, ERADICATE_NULL_METHOD_CALL, ERROR, [The value of `string` in the call to `contains(...)` could be null. (Origin: method parameter string)] +codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestPropagatesNullable.m12Bad1(), 1, ERADICATE_NULL_METHOD_CALL, ERROR, [origin,The value of `m12(...)` in the call to `length()` could be null. (Origin: call to m12(...) at line 117)] +codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestPropagatesNullable.m12Bad2(), 1, ERADICATE_NULL_METHOD_CALL, ERROR, [origin,The value of `m12(...)` in the call to `length()` could be null. (Origin: call to m12(...) at line 121)] +codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestPropagatesNullable.m2Bad(), 1, ERADICATE_NULL_METHOD_CALL, ERROR, [origin,The value of `m2(...)` in the call to `length()` could be null. (Origin: call to m2(...) at line 104)] +codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestPropagatesNullable.mBad(), 1, ERADICATE_NULL_METHOD_CALL, ERROR, [origin,The value of `m(...)` in the call to `length()` could be null. (Origin: call to m(...) at line 82)] codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestTextUtilsIsEmpty.myTextUtilsIsEmpty(CharSequence), 2, ERADICATE_NULL_METHOD_CALL, ERROR, [The value of `s` in the call to `toString()` could be null. (Origin: method parameter s)] codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestTextUtilsIsEmpty.myTextUtilsNotIsNotEmpty(CharSequence), 2, ERADICATE_NULL_METHOD_CALL, ERROR, [The value of `s` in the call to `toString()` could be null. (Origin: method parameter s)] codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestTextUtilsIsEmpty.textUtilsIsEmpty(CharSequence), 1, ERADICATE_PARAMETER_NOT_NULLABLE, ERROR, [`isEmpty(...)` needs a non-null value in parameter 1 but argument `s` can be null. (Origin: method parameter s)]