From ead4c44f9d71ab0d15024d835cb940316fd32178 Mon Sep 17 00:00:00 2001 From: Wenzhe Lu Date: Mon, 11 Mar 2019 10:51:35 -0700 Subject: [PATCH] Adding Long.parseLong model to nullsafe/modelTables.ml Reviewed By: jeremydubreil Differential Revision: D14395623 fbshipit-source-id: f643abc63 --- infer/src/nullsafe/modelTables.ml | 2 ++ .../codetoanalyze/java/eradicate/ParameterNotNullable.java | 6 ++++++ infer/tests/codetoanalyze/java/eradicate/issues.exp | 2 ++ 3 files changed, 10 insertions(+) diff --git a/infer/src/nullsafe/modelTables.ml b/infer/src/nullsafe/modelTables.ml index 030f7962a..d9c80d6e4 100644 --- a/infer/src/nullsafe/modelTables.ml +++ b/infer/src/nullsafe/modelTables.ml @@ -362,6 +362,8 @@ let annotated_list_nullable = ; ((n, [o]), "java.lang.Class.getResource(java.lang.String):java.net.URL") ; (o1, "java.lang.Class.isAssignableFrom(java.lang.Class):boolean") ; (n1, "java.lang.Integer.equals(java.lang.Object):boolean") + ; (o1, "java.lang.Integer.parseInt(java.lang.String):int") + ; (o1, "java.lang.Long.parseLong(java.lang.String):long") ; (n2, "java.lang.RuntimeException.(java.lang.String,java.lang.Throwable)") ; (n1, "java.lang.String.equals(java.lang.Object):boolean") ; (n1, "java.lang.StringBuilder.append(java.lang.String):java.lang.StringBuilder") diff --git a/infer/tests/codetoanalyze/java/eradicate/ParameterNotNullable.java b/infer/tests/codetoanalyze/java/eradicate/ParameterNotNullable.java index 75ae8a21c..3bb8c6007 100644 --- a/infer/tests/codetoanalyze/java/eradicate/ParameterNotNullable.java +++ b/infer/tests/codetoanalyze/java/eradicate/ParameterNotNullable.java @@ -180,6 +180,12 @@ public class ParameterNotNullable { ImmutableMap.copyOf(nullIterable); ImmutableMap.copyOf(nullMap); } + + void testParsingNullStringToNumber() { + String ns = null; + long l = Long.parseLong(ns); + int i = Integer.parseInt(ns); + } } interface SomeInterface { diff --git a/infer/tests/codetoanalyze/java/eradicate/issues.exp b/infer/tests/codetoanalyze/java/eradicate/issues.exp index 4afc599e9..bb4be9508 100644 --- a/infer/tests/codetoanalyze/java/eradicate/issues.exp +++ b/infer/tests/codetoanalyze/java/eradicate/issues.exp @@ -95,6 +95,8 @@ codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradi codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.testImmutableSetOfnotNullArguments():void, 7, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`ImmutableSet.of(...)` needs a non-null value in parameter 2 but argument `null` can be null. (Origin: null constant at line 151)] codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.testImmutableSetOfnotNullArguments():void, 8, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`ImmutableSet.of(...)` needs a non-null value in parameter 2 but argument `null` can be null. (Origin: null constant at line 152)] codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.testImmutableSetOfnotNullArguments():void, 8, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`ImmutableSet.of(...)` needs a non-null value in parameter 4 but argument `null` can be null. (Origin: null constant at line 152)] +codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.testParsingNullStringToNumber():void, 2, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`Long.parseLong(...)` needs a non-null value in parameter 1 but argument `ns` can be null. (Origin: null constant at line 185)] +codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.testParsingNullStringToNumber():void, 3, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`Integer.parseInt(...)` needs a non-null value in parameter 1 but argument `ns` can be null. (Origin: null constant at line 185)] 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 71)] 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 77)] codetoanalyze/java/eradicate/ParameterNotNullable.java, codetoanalyze.java.eradicate.ParameterNotNullable.testThreeParameters():void, 2, ERADICATE_PARAMETER_NOT_NULLABLE, no_bucket, WARNING, [origin,`ParameterNotNullable.threeParameters(...)` needs a non-null value in parameter 1 but argument `null` can be null. (Origin: null constant at line 88)]