From 8d36c33d2026bcfef98aaaa36b62f4dc51007539 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Tue, 14 May 2019 11:01:44 -0700 Subject: [PATCH] [eradicate] record false positive when testing the return on an assignment Reviewed By: ngorogiannis Differential Revision: D15321693 fbshipit-source-id: a6aa7068a --- .../codetoanalyze/java/eradicate/NullMethodCall.java | 11 +++++++++-- infer/tests/codetoanalyze/java/eradicate/issues.exp | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java b/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java index 36bcafe38..f03c5b925 100644 --- a/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java +++ b/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java @@ -337,14 +337,21 @@ public class NullMethodCall { void nullabilityNotPreservedAfterAssignment() { if (getNullable() != null) { Object t = getNullable(); - t.toString(); + t.toString(); // Should not warn here } } void nullabilityStoredInBooleanFP() { boolean isNotNull = getNullable() != null; if (isNotNull) { - getNullable().toString(); + getNullable().toString(); // Should not warn here + } + } + + void testInAssignmentFP(@Nullable Object object) { + Object t; + while ((t = getNullable()) != null) { + t.toString(); // Should not warn here } } } diff --git a/infer/tests/codetoanalyze/java/eradicate/issues.exp b/infer/tests/codetoanalyze/java/eradicate/issues.exp index 3aa486c2b..727c7c497 100644 --- a/infer/tests/codetoanalyze/java/eradicate/issues.exp +++ b/infer/tests/codetoanalyze/java/eradicate/issues.exp @@ -58,6 +58,7 @@ codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.N codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.nullabilityStoredInBooleanFP():void, 3, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `getNullable()` in the call to `toString()` is nullable and is not locally checked for null. (Origin: call to getNullable() at line 345)] codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testExceptionPerInstruction(int):void, 6, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `s` in the call to `length()` is nullable and is not locally checked for null. (Origin: null constant at line 180)] codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testFieldAssignmentIfThenElse(java.lang.String):void, 2, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `s` in the call to `length()` is nullable and is not locally checked for null. (Origin: null constant at line 171)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testInAssignmentFP(java.lang.Object):void, 3, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `t` in the call to `toString()` is nullable and is not locally checked for null. (Origin: call to getNullable() at line 353)] codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testMapGetBad(java.util.Map,java.util.HashMap,java.util.concurrent.ConcurrentHashMap):void, 2, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `m.get(...)` in the call to `toString()` is nullable and is not locally checked for null. (Origin: call to get(...) modelled in modelTables.ml at line 259)] codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testMapGetBad(java.util.Map,java.util.HashMap,java.util.concurrent.ConcurrentHashMap):void, 3, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `hm.get(...)` in the call to `toString()` is nullable and is not locally checked for null. (Origin: call to get(...) modelled in modelTables.ml at line 260)] codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testMapGetBad(java.util.Map,java.util.HashMap,java.util.concurrent.ConcurrentHashMap):void, 4, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `chm.get(...)` in the call to `toString()` is nullable and is not locally checked for null. (Origin: call to get(...) modelled in modelTables.ml at line 261)]