diff --git a/infer/src/nullsafe/models.ml b/infer/src/nullsafe/models.ml index 94dab3f9c..740030b61 100644 --- a/infer/src/nullsafe/models.ml +++ b/infer/src/nullsafe/models.ml @@ -64,9 +64,7 @@ let is_check_not_null proc_name = (** Parameter number for a procedure known to be a checkNotNull *) let get_check_not_null_parameter proc_name = let proc_id = Typ.Procname.to_unique_id proc_name in - try Hashtbl.find check_not_null_parameter_table proc_id with Caml.Not_found -> - (* Assume the check is on the first parameter unless modeled otherwise *) - 1 + Hashtbl.find_opt check_not_null_parameter_table proc_id (** Check if the procedure is one of the known Preconditions.checkState. *) diff --git a/infer/src/nullsafe/typeCheck.ml b/infer/src/nullsafe/typeCheck.ml index e683de067..f325d534c 100644 --- a/infer/src/nullsafe/typeCheck.ml +++ b/infer/src/nullsafe/typeCheck.ml @@ -800,13 +800,15 @@ let typecheck_instr tenv calls_this checks (node : Procdesc.Node.t) idenv curr_p EradicateChecks.check_call_parameters tenv find_canonical_duplicate curr_pdesc node callee_attributes resolved_params loc instr_ref ; if Models.is_check_not_null callee_pname then - if Typ.Procname.Java.is_vararg callee_pname_java then - let last_parameter = List.length call_params in - do_preconditions_check_not_null last_parameter ~is_vararg:true typestate1 - else - do_preconditions_check_not_null - (Models.get_check_not_null_parameter callee_pname) - ~is_vararg:false typestate1 + match Models.get_check_not_null_parameter callee_pname with + | Some index -> + do_preconditions_check_not_null index ~is_vararg:false typestate1 + | None when Typ.Procname.Java.is_vararg callee_pname_java -> + let last_parameter = List.length call_params in + do_preconditions_check_not_null last_parameter ~is_vararg:true typestate1 + | None -> + (* assume the first parameter is checked for null *) + do_preconditions_check_not_null 1 ~is_vararg:false typestate1 else if Models.is_check_state callee_pname || Models.is_check_argument callee_pname then do_preconditions_check_state typestate1 else if Models.is_mapPut callee_pname then do_map_put typestate1