diff --git a/infer/man/man1/infer-full.txt b/infer/man/man1/infer-full.txt index c46ef0c68..2636d1181 100644 --- a/infer/man/man1/infer-full.txt +++ b/infer/man/man1/infer-full.txt @@ -1271,6 +1271,10 @@ INTERNAL OPTIONS --nullable-annotation-name-reset Cancel the effect of --nullable-annotation-name. + --nullsafe-strict-containers + Activates: Warn when containers are used with nullable keys or + values (Conversely: --no-nullsafe-strict-containers) + --no-only-cheap-debug Deactivates: Disable expensive debugging output (Conversely: --only-cheap-debug) diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index c636c954a..29325296c 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -1639,6 +1639,11 @@ and nullable_annotation = CLOpt.mk_string_opt ~long:"nullable-annotation-name" "Specify custom nullable annotation name" +and nullsafe_strict_containers = + CLOpt.mk_bool ~long:"nullsafe-strict-containers" ~default:false + "Warn when containers are used with nullable keys or values" + + and only_footprint = CLOpt.mk_bool ~deprecated:["only_footprint"] ~long:"only-footprint" "Skip the re-execution phase" @@ -2777,6 +2782,8 @@ and nelseg = !nelseg and nullable_annotation = !nullable_annotation +and nullsafe_strict_containers = !nullsafe_strict_containers + and no_translate_libs = not !headers and only_cheap_debug = !only_cheap_debug diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index b02ff569d..65219305d 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -498,6 +498,8 @@ val no_translate_libs : bool val nullable_annotation : string option +val nullsafe_strict_containers : bool + val only_cheap_debug : bool val only_footprint : bool diff --git a/infer/src/nullsafe/modelTables.ml b/infer/src/nullsafe/modelTables.ml index fc3043c0e..42d7fb336 100644 --- a/infer/src/nullsafe/modelTables.ml +++ b/infer/src/nullsafe/modelTables.ml @@ -12,8 +12,6 @@ module Hashtbl = Caml.Hashtbl * This file is a big bunch of tables; they read better with really long lines. * @nolint *) -(* in strict mode cannot insert null in containers *) -let strict_containers = false (* in strict mode, give an error if a nullable is passed to checkNotNull *) let check_not_null_strict = false @@ -45,16 +43,16 @@ let n3 = (o, [n; n; n]) let on = (o, [o; n]) (* container add *) -let ca = if strict_containers then (o, [o]) else (o, [n]) +let ca = if Config.nullsafe_strict_containers then (o, [o]) else (o, [n]) (* container get *) -let cg = if strict_containers then (n, [o]) else (n, [n]) +let cg = if Config.nullsafe_strict_containers then (n, [o]) else (n, [n]) (* container put *) -let cp = (n, [o; o]) +let cp = if Config.nullsafe_strict_containers then (n, [o; o]) else (n, [n; n]) (* container remove *) -let cr = if strict_containers then (n, [o]) else (n, [n]) +let cr = if Config.nullsafe_strict_containers then (n, [o]) else (n, [n]) (* nullable getter *) let ng = (n, []) diff --git a/infer/tests/codetoanalyze/java/eradicate/.inferconfig b/infer/tests/codetoanalyze/java/eradicate/.inferconfig index 984517f70..9914a46a4 100644 --- a/infer/tests/codetoanalyze/java/eradicate/.inferconfig +++ b/infer/tests/codetoanalyze/java/eradicate/.inferconfig @@ -1,5 +1,6 @@ { "external-java-packages": [ "external." - ] + ], + "nullsafe-strict-containers": true }