diff --git a/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java b/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java index 2f163c9c3..24e1409d3 100644 --- a/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java +++ b/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java @@ -280,4 +280,18 @@ public class NullMethodCall { chm.remove("foo").toString(); } + @Nullable Object nullableField; + + void FP_propagatesNonNullAfterComparisonFieldOkay(Object nonNullObject) { + if (nullableField == nonNullObject) { + nullableField.toString(); + } + } + + void FP_propagatesNonNullAfterComparisonParameterOkay( + @Nullable Object nullableParameter, Object nonNullParameter) { + if (nullableParameter == nonNullParameter) { + nullableParameter.toString(); + } + } } diff --git a/infer/tests/codetoanalyze/java/eradicate/issues.exp b/infer/tests/codetoanalyze/java/eradicate/issues.exp index ed2691b29..6e7e917f5 100644 --- a/infer/tests/codetoanalyze/java/eradicate/issues.exp +++ b/infer/tests/codetoanalyze/java/eradicate/issues.exp @@ -40,6 +40,8 @@ codetoanalyze/java/eradicate/NullFieldAccess.java, int NullFieldAccess.useZ(), 2 codetoanalyze/java/eradicate/NullMethodCall.java, int NullMethodCall$Inner.outerField(), 2, ERADICATE_NULL_METHOD_CALL, [origin,The value of `s` in the call to `length()` could be null. (Origin: field NullMethodCall.fld at line 74)] codetoanalyze/java/eradicate/NullMethodCall.java, int NullMethodCall$Inner.outerPrivateField(), 2, ERADICATE_NULL_METHOD_CALL, [origin,The value of `s` in the call to `length()` could be null. (Origin: field NullMethodCall.pfld at line 85)] codetoanalyze/java/eradicate/NullMethodCall.java, int NullMethodCall.testSystemGetenvBad(), 2, ERADICATE_NULL_METHOD_CALL, [origin,The value of `envValue` in the call to `length()` could be null. (Origin: call to getenv(...) modelled in modelTables.ml at line 246)] +codetoanalyze/java/eradicate/NullMethodCall.java, void NullMethodCall.FP_propagatesNonNullAfterComparisonFieldOkay(Object), 2, ERADICATE_NULL_METHOD_CALL, [origin,The value of `NullMethodCall.nullableField` in the call to `toString()` could be null. (Origin: field NullMethodCall.nullableField at line 286)] +codetoanalyze/java/eradicate/NullMethodCall.java, void NullMethodCall.FP_propagatesNonNullAfterComparisonParameterOkay(Object,Object), 3, ERADICATE_NULL_METHOD_CALL, [The value of `nullableParameter` in the call to `toString()` could be null. (Origin: method parameter nullableParameter)] codetoanalyze/java/eradicate/NullMethodCall.java, void NullMethodCall.callOnNull(), 2, ERADICATE_NULL_METHOD_CALL, [origin,The value of `s` in the call to `length()` could be null. (Origin: null constant at line 25)] codetoanalyze/java/eradicate/NullMethodCall.java, void NullMethodCall.testExceptionPerInstruction(int), 6, ERADICATE_NULL_METHOD_CALL, [origin,The value of `s` in the call to `length()` could be null. (Origin: null constant at line 186)] codetoanalyze/java/eradicate/NullMethodCall.java, void NullMethodCall.testFieldAssignmentIfThenElse(String), 2, ERADICATE_NULL_METHOD_CALL, [origin,The value of `s` in the call to `length()` could be null. (Origin: null constant at line 177)]