diff --git a/infer/src/nullsafe/ErrorRenderingUtils.ml b/infer/src/nullsafe/ErrorRenderingUtils.ml index c01ca4a3f..5afcdc8b5 100644 --- a/infer/src/nullsafe/ErrorRenderingUtils.ml +++ b/infer/src/nullsafe/ErrorRenderingUtils.ml @@ -69,7 +69,7 @@ let is_object_nullability_self_explanatory ~object_expression (object_origin : T Latter case is self-explanatory: it is easy to the user to jump to definition and check out the method annotation. *) - let method_name = Procname.to_simplified_string pname in + let method_name = Procname.Java.to_simplified_string pname in String.is_suffix object_expression ~suffix:method_name | ThirdParty ModelledInternally | ThirdParty (InThirdPartyRepo _) -> (* This is non-trivial and should always be explained to the user *) @@ -96,14 +96,6 @@ type message_info = ; recommendation: string ; issue_type: IssueType.t } -let get_method_class_name procname = - match procname with - | Procname.Java java_pname -> - Some (Procname.Java.get_simple_class_name java_pname) - | _ -> - None - - let get_field_class_name field_name = let class_with_field = Fieldname.to_simplified_string field_name in String.rsplit2 class_with_field ~on:'.' @@ -163,7 +155,7 @@ let get_info object_origin nullsafe_mode untrusted_kind = | TypeOrigin.MethodCall {pname; call_loc} -> let offending_object = F.asprintf "%a" MarkupFormatter.pp_monospaced - (Procname.to_simplified_string ~withclass:true pname) + (Procname.Java.to_simplified_string ~withclass:true pname) in let object_loc = call_loc in let what_is_used = "Result of this call" in @@ -171,7 +163,7 @@ let get_info object_origin nullsafe_mode untrusted_kind = match untrusted_kind with | UserFriendlyNullable.ThirdPartyNonnull -> let suggested_third_party_sig_file = - ThirdPartyAnnotationInfo.lookup_related_sig_file_for_proc + ThirdPartyAnnotationInfo.lookup_related_sig_file_for_java_proc (ThirdPartyAnnotationGlobalRepo.get_repo ()) pname in @@ -191,9 +183,7 @@ let get_info object_origin nullsafe_mode untrusted_kind = mk_coming_from_unchecked_or_locally_checked_case_only nullsafe_mode untrusted_kind in let recommendation = - let what_to_strictify = - Option.value (get_method_class_name pname) ~default:offending_object - in + let what_to_strictify = Procname.Java.get_simple_class_name pname in mk_strictification_advice_unchecked_or_locally_checked_case_only nullsafe_mode untrusted_kind ~what_to_strictify in @@ -269,11 +259,11 @@ let mk_nullsafe_issue_for_untrusted_values ~nullsafe_mode ~untrusted_kind ~bad_u let find_alternative_nonnull_method_description nullable_origin = let open IOption.Let_syntax in match nullable_origin with - | TypeOrigin.MethodCall {pname= Procname.Java java_pname as pname} -> + | TypeOrigin.MethodCall {pname} -> let* ModelTables.{package_name; class_name; method_name} = Models.find_nonnullable_alternative pname in - let+ original_package_name = Procname.Java.get_package java_pname in + let+ original_package_name = Procname.Java.get_package pname in if String.equal original_package_name package_name then (* The same package that is from origin - omit name for simplicity *) class_name ^ "." ^ method_name ^ "()" diff --git a/infer/src/nullsafe/models.ml b/infer/src/nullsafe/models.ml index ef5d2ff51..4f9ed6723 100644 --- a/infer/src/nullsafe/models.ml +++ b/infer/src/nullsafe/models.ml @@ -149,9 +149,10 @@ let is_mapPut proc_name = table_has_procedure mapPut_table proc_name (** Check if a (nullable) method has a non-nullable alternative: A method that does the same as [proc_name] but asserts the result is not null before returning to the caller. *) -let find_nonnullable_alternative proc_name = +let find_nonnullable_alternative java_proc_name = (* NOTE: For now we fetch this info from internal models. It is a good idea to support this feature in a user-facing third party repository. *) + let proc_name = Procname.Java java_proc_name in let proc_id = Procname.to_unique_id proc_name in Hashtbl.find_opt nonnull_alternatives_table proc_id diff --git a/infer/src/nullsafe/typeCheck.ml b/infer/src/nullsafe/typeCheck.ml index bb2f6808c..6a2510915 100644 --- a/infer/src/nullsafe/typeCheck.ml +++ b/infer/src/nullsafe/typeCheck.ml @@ -997,8 +997,7 @@ let calc_typestate_after_call ({IntraproceduralAnalysis.proc_desc= curr_pdesc; tenv; _} as analysis_data) find_canonical_duplicate calls_this checks idenv instr_ref signature_params cflags call_params ~is_anonymous_inner_class_constructor ~callee_annotated_signature ~callee_attributes - ~callee_pname ~callee_pname_java ~curr_annotated_signature ~nullsafe_mode ~typestate ~typestate1 - loc node = + ~callee_pname ~curr_annotated_signature ~nullsafe_mode ~typestate ~typestate1 loc node = let resolve_param i (formal_param, actual_param) = let (orig_e2, e2), t2 = actual_param in let _, inferred_nullability_actual = @@ -1058,19 +1057,18 @@ let calc_typestate_after_call if not is_anonymous_inner_class_constructor then ( if cflags.CallFlags.cf_virtual && checks.eradicate then EradicateChecks.check_call_receiver analysis_data ~nullsafe_mode find_canonical_duplicate - node typestate1 call_params callee_pname_java instr_ref loc + node typestate1 call_params callee_pname instr_ref loc (typecheck_expr analysis_data ~nullsafe_mode find_canonical_duplicate calls_this checks) ; if checks.eradicate then - EradicateChecks.check_call_parameters ~callee_pname:callee_pname_java analysis_data - ~nullsafe_mode ~callee_annotated_signature find_canonical_duplicate node resolved_params - loc instr_ref ; - if Models.is_check_not_null callee_pname then - match Models.get_check_not_null_parameter callee_pname with + EradicateChecks.check_call_parameters ~callee_pname analysis_data ~nullsafe_mode + ~callee_annotated_signature find_canonical_duplicate node resolved_params loc instr_ref ; + if Models.is_check_not_null (Procname.Java callee_pname) then + match Models.get_check_not_null_parameter (Procname.Java callee_pname) with | Some index -> do_preconditions_check_not_null analysis_data instr_ref find_canonical_duplicate node loc curr_annotated_signature checks call_params idenv index ~is_vararg:false typestate1 - | None when Procname.Java.is_vararg callee_pname_java -> + | None when Procname.Java.is_vararg callee_pname -> let last_parameter = List.length call_params in do_preconditions_check_not_null analysis_data instr_ref find_canonical_duplicate node loc curr_annotated_signature checks call_params idenv last_parameter ~is_vararg:true @@ -1079,13 +1077,16 @@ let calc_typestate_after_call (* assume the first parameter is checked for null *) do_preconditions_check_not_null analysis_data instr_ref find_canonical_duplicate node loc curr_annotated_signature checks call_params idenv 1 ~is_vararg:false typestate1 - else if Models.is_check_state callee_pname || Models.is_check_argument callee_pname then + else if + Models.is_check_state (Procname.Java callee_pname) + || Models.is_check_argument (Procname.Java callee_pname) + then let curr_pname = Procdesc.get_proc_name curr_pdesc in do_preconditions_check_state instr_ref idenv tenv curr_pname curr_annotated_signature call_params loc node typestate1 - else if Models.is_mapPut callee_pname then - do_map_put analysis_data call_params callee_pname loc node calls_this checks instr_ref - ~nullsafe_mode find_canonical_duplicate typestate1 + else if Models.is_mapPut (Procname.Java callee_pname) then + do_map_put analysis_data call_params (Procname.Java callee_pname) loc node calls_this checks + instr_ref ~nullsafe_mode find_canonical_duplicate typestate1 else typestate1 ) else typestate1 in @@ -1175,7 +1176,7 @@ let typecheck_sil_call_function let typestate_after_call, finally_resolved_ret = calc_typestate_after_call analysis_data find_canonical_duplicate calls_this checks idenv instr_ref signature_params cflags call_params ~is_anonymous_inner_class_constructor - ~callee_annotated_signature ~callee_attributes ~callee_pname ~callee_pname_java + ~callee_annotated_signature ~callee_attributes ~callee_pname:callee_pname_java ~curr_annotated_signature ~nullsafe_mode ~typestate ~typestate1 loc node in do_return finally_resolved_ret typestate_after_call ) diff --git a/infer/src/nullsafe/typeErr.ml b/infer/src/nullsafe/typeErr.ml index 8b67cf8ab..71b672705 100644 --- a/infer/src/nullsafe/typeErr.ml +++ b/infer/src/nullsafe/typeErr.ml @@ -219,7 +219,7 @@ let get_nonnull_explanation_for_condition_redudant (nonnull_origin : TypeOrigin. match nonnull_origin with | MethodCall {pname} -> Format.asprintf ": %a is not annotated as `@Nullable`" MF.pp_monospaced - (Procname.to_simplified_string ~withclass:true pname) + (Procname.Java.to_simplified_string ~withclass:true pname) | NullConst _ -> Logging.die Logging.InternalError "Unexpected origin NullConst: this is for nullable types, should not lead to condition \ diff --git a/infer/src/nullsafe/typeOrigin.ml b/infer/src/nullsafe/typeOrigin.ml index f2cf948e3..e1af499d2 100644 --- a/infer/src/nullsafe/typeOrigin.ml +++ b/infer/src/nullsafe/typeOrigin.ml @@ -23,7 +23,7 @@ type t = | CurrMethodParameter of method_parameter_origin | This | MethodCall of - { pname: Procname.t + { pname: Procname.Java.t ; call_loc: Location.t ; annotated_signature: AnnotatedSignature.t ; is_defined: bool } @@ -96,7 +96,7 @@ let rec to_string = function | This -> "this" | MethodCall {pname} -> - Printf.sprintf "Fun %s" (Procname.to_simplified_string pname) + Printf.sprintf "Fun %s" (Procname.Java.to_simplified_string pname) | CallToGetKnownToContainsKey -> "CallToGetKnownToContainsKey" | New -> @@ -152,7 +152,7 @@ let get_method_ret_description pname call_loc line_number in Format.sprintf "call to %s%s%s" - (Procname.to_simplified_string ~withclass:should_show_class_name pname) + (Procname.Java.to_simplified_string ~withclass:should_show_class_name pname) (atline call_loc) model_info diff --git a/infer/src/nullsafe/typeOrigin.mli b/infer/src/nullsafe/typeOrigin.mli index f1611a35a..b3a0e7e48 100644 --- a/infer/src/nullsafe/typeOrigin.mli +++ b/infer/src/nullsafe/typeOrigin.mli @@ -22,7 +22,7 @@ type t = (** Parameter of a method we are currently in, *) | This (* `this` object. Can not be null, according to Java rules. *) | MethodCall of - { pname: Procname.t + { pname: Procname.Java.t ; call_loc: Location.t ; annotated_signature: AnnotatedSignature.t ; is_defined: bool } (** A result of a method call *)