From 24bd229adacc1547fcbf945319c6f163702adc38 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Wed, 19 Dec 2018 07:29:26 -0800 Subject: [PATCH] [infer][eradicate] example of error messages involving the temporary variables used to translate logical operations and conditional assignment Reviewed By: ezgicicek Differential Revision: D13516477 fbshipit-source-id: 37096f273 --- .../java/eradicate/NullMethodCall.java | 15 +++++++++++++++ .../java/eradicate/ParameterNotNullable.java | 10 ++++++++++ .../tests/codetoanalyze/java/eradicate/issues.exp | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java b/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java index 11fac7759..a8cc6a553 100644 --- a/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java +++ b/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java @@ -293,4 +293,19 @@ public class NullMethodCall { String callingSeverSideNullableGetter(ServerSideDeserializer deserializer) { return deserializer.nullableGetter().toString(); } + + interface AnotherI { + void withBooleanParameter(boolean test); + + void withObjectParameter(Object object); + } + + void withConjuction(@Nullable AnotherI i, boolean test1, boolean test2) { + i.withBooleanParameter(test1 && test2); + } + + void withConditionalAssignemnt( + @Nullable AnotherI i, boolean test, Object object1, Object object2) { + i.withObjectParameter(test ? object1 : object2); + } } diff --git a/infer/tests/codetoanalyze/java/eradicate/ParameterNotNullable.java b/infer/tests/codetoanalyze/java/eradicate/ParameterNotNullable.java index b058b50e4..4506a18c1 100644 --- a/infer/tests/codetoanalyze/java/eradicate/ParameterNotNullable.java +++ b/infer/tests/codetoanalyze/java/eradicate/ParameterNotNullable.java @@ -99,6 +99,16 @@ public class ParameterNotNullable { void indirectSignatureLookupOk(SomeClass c) { c.acceptsNullableParameter(null); } + + void doesNotAcceptNullableFirstParameter(Object object, boolean test) {} + + void callWithNullableFirstParameter(boolean t1, boolean t2) { + doesNotAcceptNullableFirstParameter(null, t1 && t2); + } + + void callWithConditionalAssignment(Object object, boolean test) { + doesNotAcceptNullableFirstParameter(test ? object : null, test); + } } interface SomeInterface { diff --git a/infer/tests/codetoanalyze/java/eradicate/issues.exp b/infer/tests/codetoanalyze/java/eradicate/issues.exp index 8ca18135e..2f2211aaa 100644 --- a/infer/tests/codetoanalyze/java/eradicate/issues.exp +++ b/infer/tests/codetoanalyze/java/eradicate/issues.exp @@ -63,9 +63,13 @@ codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.N codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testMapRemoveBad(java.util.Map,java.util.HashMap,java.util.concurrent.ConcurrentHashMap):void, 4, ERADICATE_NULL_METHOD_CALL, no_bucket, WARNING, [origin,The value of `chm.remove(...)` in the call to `toString()` is nullable and is not locally checked for null. (Origin: call to remove(...) modelled in modelTables.ml at line 266)] codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testSystemGetPropertyReturn():void, 2, ERADICATE_NULL_METHOD_CALL, no_bucket, WARNING, [origin,The value of `s` in the call to `length()` is nullable and is not locally checked for null. (Origin: call to getProperty(...) modelled in modelTables.ml at line 232)] codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testSystemGetenvBad():int, 2, ERADICATE_NULL_METHOD_CALL, no_bucket, WARNING, [origin,The value of `envValue` in the call to `length()` is nullable and is not locally checked for null. (Origin: call to getenv(...) modelled in modelTables.ml at line 237)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.withConditionalAssignemnt(codetoanalyze.java.eradicate.NullMethodCall$AnotherI,boolean,java.lang.Object,java.lang.Object):void, 2, ERADICATE_NULL_METHOD_CALL, no_bucket, WARNING, [The value of `$T1_11` in the call to `withObjectParameter(...)` is nullable and is not locally checked for null. (Origin: method parameter i)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.withConjuction(codetoanalyze.java.eradicate.NullMethodCall$AnotherI,boolean,boolean):void, 1, ERADICATE_NULL_METHOD_CALL, no_bucket, WARNING, [The value of `$T1_14` in the call to `withBooleanParameter(...)` is nullable and is not locally checked for null. (Origin: method parameter i)] codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable$ConstructorCall.(codetoanalyze.java.eradicate.ParameterNotNullable,int), 1, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`ParameterNotNullable$ConstructorCall(...)` needs a non-null value in parameter 2 but argument `null` can be null. (Origin: null constant at line 95)] codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.callNull():void, 2, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`ParameterNotNullable.test(...)` needs a non-null value in parameter 1 but argument `s` can be null. (Origin: null constant at line 33)] codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.callNullable(java.lang.String):void, 1, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [`ParameterNotNullable.test(...)` needs a non-null value in parameter 1 but argument `s` can be null. (Origin: method parameter s)] +codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.callWithConditionalAssignment(java.lang.Object,boolean):void, 1, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`ParameterNotNullable.doesNotAcceptNullableFirstParameter(...)` needs a non-null value in parameter 1 but argument `$T0_10` can be null. (Origin: null constant at line 110)] +codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.callWithNullableFirstParameter(boolean,boolean):void, 1, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`ParameterNotNullable.doesNotAcceptNullableFirstParameter(...)` needs a non-null value in parameter 1 but argument `$T1_15` can be null. (Origin: null constant at line 106)] codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.testClassGetResourceArgument(java.lang.Class):java.net.URL, 1, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`Class.getResource(...)` needs a non-null value in parameter 1 but argument `null` can be null. (Origin: null constant at line 75)] codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.testSystemGetPropertyArgument():java.lang.String, 1, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`System.getProperty(...)` needs a non-null value in parameter 1 but argument `null` can be null. (Origin: null constant at line 65)] codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.testSystemGetenvBad():java.lang.String, 1, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`System.getenv(...)` needs a non-null value in parameter 1 but argument `null` can be null. (Origin: null constant at line 71)]