From 79b0b8172d5038f41f119e12316e4a462ce829ce Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Wed, 22 May 2019 02:21:06 -0700 Subject: [PATCH] [eradicate] add a model for java.nio.file.Path.getParent() Reviewed By: ezgicicek Differential Revision: D15447277 fbshipit-source-id: ed7f61940 --- infer/src/nullsafe/modelTables.ml | 1 + .../java/eradicate/NullMethodCall.java | 5 +++ .../codetoanalyze/java/eradicate/issues.exp | 37 ++++++++++--------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/infer/src/nullsafe/modelTables.ml b/infer/src/nullsafe/modelTables.ml index d9c80d6e4..3bdf0d18d 100644 --- a/infer/src/nullsafe/modelTables.ml +++ b/infer/src/nullsafe/modelTables.ml @@ -372,6 +372,7 @@ let annotated_list_nullable = ; ( on , "java.net.URLClassLoader.newInstance(java.net.URL[],java.lang.ClassLoader):java.net.URLClassLoader" ) + ; (ng, "java.nio.file.Path.getParent():java.nio.file.Path") ; (n1, "java.util.AbstractList.equals(java.lang.Object):boolean") ; (ca, "java.util.ArrayList.add(java.lang.Object):boolean") ; (ca, "java.util.List.add(java.lang.Object):boolean") diff --git a/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java b/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java index f03c5b925..dba8e5df2 100644 --- a/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java +++ b/infer/tests/codetoanalyze/java/eradicate/NullMethodCall.java @@ -12,6 +12,7 @@ import android.app.PendingIntent; import com.facebook.infer.annotation.Assertions; import com.google.common.base.Preconditions; import com.google.common.base.Verify; +import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -354,4 +355,8 @@ public class NullMethodCall { t.toString(); // Should not warn here } } + + String testPathGetParent() { + return Paths.get("foo").getParent().toString(); + } } diff --git a/infer/tests/codetoanalyze/java/eradicate/issues.exp b/infer/tests/codetoanalyze/java/eradicate/issues.exp index a39bf3cad..f1dccb0bf 100644 --- a/infer/tests/codetoanalyze/java/eradicate/issues.exp +++ b/infer/tests/codetoanalyze/java/eradicate/issues.exp @@ -47,26 +47,27 @@ codetoanalyze/java/eradicate/NullFieldAccess.java, codetoanalyze.java.eradicate. codetoanalyze/java/eradicate/NullFieldAccess.java, codetoanalyze.java.eradicate.NullFieldAccess.useInterface(codetoanalyze.java.eradicate.NullFieldAccess$I):int, 2, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [Object `c` is nullable and is not locally checked for null when accessing field `NullFieldAccess$C.n`. (Origin: field NullFieldAccess$I.c at line 45)] codetoanalyze/java/eradicate/NullFieldAccess.java, codetoanalyze.java.eradicate.NullFieldAccess.useX():int, 2, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [Object `c` is nullable and is not locally checked for null when accessing field `NullFieldAccess$C.n`. (Origin: field NullFieldAccess.x at line 30)] codetoanalyze/java/eradicate/NullFieldAccess.java, codetoanalyze.java.eradicate.NullFieldAccess.useZ():int, 2, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [Object `c` is nullable and is not locally checked for null when accessing field `NullFieldAccess$C.n`. (Origin: field NullFieldAccess.z at line 40)] -codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall$Inner.outerField():int, 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: field NullMethodCall.fld at line 68)] -codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall$Inner.outerPrivateField():int, 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: field NullMethodCall.pfld at line 79)] -codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.FP_propagatesNonNullAfterComparisonFieldOkay(java.lang.Object):void, 2, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `NullMethodCall.nullableField` in the call to `toString()` is nullable and is not locally checked for null. (Origin: field NullMethodCall.nullableField at line 274)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall$Inner.outerField():int, 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: field NullMethodCall.fld at line 69)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall$Inner.outerPrivateField():int, 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: field NullMethodCall.pfld at line 80)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.FP_propagatesNonNullAfterComparisonFieldOkay(java.lang.Object):void, 2, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `NullMethodCall.nullableField` in the call to `toString()` is nullable and is not locally checked for null. (Origin: field NullMethodCall.nullableField at line 275)] codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.FP_propagatesNonNullAfterComparisonParameterOkay(java.lang.Object,java.lang.Object):void, 3, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `nullableParameter` in the call to `toString()` is nullable and is not locally checked for null. (Origin: method parameter nullableParameter)] -codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.callOnNull():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 24)] -codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.callingSeverSideNullableGetter(codetoanalyze.java.eradicate.ServerSideDeserializer):java.lang.String, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, ERROR, [The value of `deserializer.nullableGetter()` in the call to `toString()` is nullable and is not locally checked for null. (Origin: call to nullableGetter() at line 306)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.callOnNull():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 25)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.callingSeverSideNullableGetter(codetoanalyze.java.eradicate.ServerSideDeserializer):java.lang.String, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, ERROR, [The value of `deserializer.nullableGetter()` in the call to `toString()` is nullable and is not locally checked for null. (Origin: call to nullableGetter() at line 307)] codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.nullMethodCallWithAlarmManager(android.app.AlarmManager,android.app.PendingIntent):void, 1, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [`AlarmManager.cancel(...)` needs a non-null value in parameter 1 but argument `intent` can be null. (Origin: method parameter intent)] -codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.nullabilityNotPreservedAfterAssignment():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 339)] -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)] -codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testMapRemoveBad(java.util.Map,java.util.HashMap,java.util.concurrent.ConcurrentHashMap):void, 2, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `m.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.testMapRemoveBad(java.util.Map,java.util.HashMap,java.util.concurrent.ConcurrentHashMap):void, 3, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `hm.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 267)] -codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testMapRemoveBad(java.util.Map,java.util.HashMap,java.util.concurrent.ConcurrentHashMap):void, 4, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [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 268)] -codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testSystemGetPropertyReturn():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: call to getProperty(...) modelled in modelTables.ml at line 234)] -codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testSystemGetenvBad():int, 2, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [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 239)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.nullabilityNotPreservedAfterAssignment():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 340)] +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 346)] +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 181)] +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 172)] +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 354)] +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 260)] +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 261)] +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 262)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testMapRemoveBad(java.util.Map,java.util.HashMap,java.util.concurrent.ConcurrentHashMap):void, 2, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `m.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 267)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testMapRemoveBad(java.util.Map,java.util.HashMap,java.util.concurrent.ConcurrentHashMap):void, 3, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `hm.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 268)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testMapRemoveBad(java.util.Map,java.util.HashMap,java.util.concurrent.ConcurrentHashMap):void, 4, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [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 269)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testPathGetParent():java.lang.String, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `get(...).getParent()` in the call to `toString()` is nullable and is not locally checked for null. (Origin: call to getParent() modelled in modelTables.ml at line 360)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testSystemGetPropertyReturn():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: call to getProperty(...) modelled in modelTables.ml at line 235)] +codetoanalyze/java/eradicate/NullMethodCall.java, codetoanalyze.java.eradicate.NullMethodCall.testSystemGetenvBad():int, 2, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [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 240)] 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_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `i` 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_NULLABLE_DEREFERENCE, no_bucket, WARNING, [The value of `i` 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, [`ParameterNotNullable$ConstructorCall(...)` needs a non-null value in parameter 2 but argument `null` can be null. (Origin: null constant at line 101)]