[eradicate] model com.google.common.base.Strings.isNullOrEmpty(...)

Reviewed By: sblackshear

Differential Revision: D7526376

fbshipit-source-id: da60808
master
Jeremy Dubreil 7 years ago committed by Facebook Github Bot
parent 431d4f1290
commit 2f1d486aab

@ -158,7 +158,8 @@ let optional_isPresent_list : ((_ * bool list) * _) list =
(** Models for boolean functions that return true on null. *) (** Models for boolean functions that return true on null. *)
let true_on_null_list : ((_ * bool list) * _) list = 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 *) (** Models for Map.containsKey *)

@ -16,7 +16,7 @@ import com.facebook.infer.annotation.Assertions;
import com.facebook.infer.annotation.FalseOnNull; import com.facebook.infer.annotation.FalseOnNull;
import com.facebook.infer.annotation.PropagatesNullable; import com.facebook.infer.annotation.PropagatesNullable;
import com.facebook.infer.annotation.TrueOnNull; import com.facebook.infer.annotation.TrueOnNull;
import com.google.common.base.Strings;
public class CustomAnnotations { public class CustomAnnotations {
@ -70,7 +70,6 @@ public class CustomAnnotations {
} }
} }
// Tests for the annotation @PropagatesNullable // Tests for the annotation @PropagatesNullable
class TestPropagatesNullable { class TestPropagatesNullable {
@ -126,4 +125,19 @@ public class CustomAnnotations {
m12("", "").length(); 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");
}
}
}
} }

@ -1,8 +1,9 @@
codetoanalyze/java/eradicate/ActivityFieldNotInitialized.java, ActivityFieldNotInitialized$BadActivityWithOnCreate.<init>(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/ActivityFieldNotInitialized.java, ActivityFieldNotInitialized$BadActivityWithOnCreate.<init>(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$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.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.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.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.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.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$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.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.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)] 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)]

Loading…
Cancel
Save