[nullsafe] Respect external models when decide wether to report on passing wrong param or not

Summary:
This is a dirty hack to make nullsafe behave consistently for internal
and external models.

Medium term this code needs to be rewritten in a better way, so that we
pass all information in annotated signature (either in form of Inferred
nullability, or type origin, which tracks third party calls).

As a follow up, we will make reporting more clear.

Reviewed By: artempyanykh

Differential Revision: D18372660

fbshipit-source-id: 12c2449e1
master
Mitya Lyubarskiy 5 years ago committed by Facebook Github Bot
parent f303c9fa87
commit 42397d2168

@ -443,7 +443,8 @@ let check_call_parameters ~is_strict_mode tenv find_canonical_duplicate curr_pde
(* TODO(T52947663) model is_external as unknown nullability and move the logic out of this check *)
(* If method is external, we don't check it, unless it is explicitly modelled *)
(not (Typ.Procname.Java.is_external java_pname))
|| Models.is_modelled_for_nullability callee_pname
|| Models.is_modelled_for_nullability_as_internal callee_pname
|| Models.is_modelled_for_nullability_as_external callee_pname
| _ ->
false
in

@ -96,7 +96,10 @@ let get_modelled_annotated_signature tenv proc_attributes =
(** Return true when the procedure has been modelled for nullability. *)
let is_modelled_for_nullability proc_name =
let is_modelled_for_nullability_as_internal proc_name =
(* TODO: get rid of this function, and propagate this information in get_modelled_annotated_signature instead
to avoid double calculation and make the code more clear.
*)
let proc_id = Typ.Procname.to_unique_id proc_name in
try
ignore (Hashtbl.find annotated_table_nullability proc_id) ;
@ -104,6 +107,19 @@ let is_modelled_for_nullability proc_name =
with Caml.Not_found -> false
(** Return true when the procedure has been modelled for nullability as external third-party code. *)
let is_modelled_for_nullability_as_external proc_name =
(* TODO: get rid of this function, and propagate this information in get_modelled_annotated_signature instead
to avoid double calculation and make the code more clear.
*)
get_unique_repr proc_name
|> Option.map
~f:
(ThirdPartyAnnotationInfo.find_nullability_info
(ThirdPartyAnnotationGlobalRepo.get_repo ()))
|> Option.is_some
(** Check if the procedure is one of the known Preconditions.checkNotNull. *)
let is_check_not_null proc_name =
table_has_procedure check_not_null_table proc_name || match_method_name proc_name "checkNotNull"

@ -57,7 +57,8 @@ let get_description origin =
| Proc po ->
let modelled_in =
(* TODO(T54088319) don't calculate this info and propagate it from AnnotatedNullability instead *)
if Models.is_modelled_for_nullability po.pname then " modelled in " ^ ModelTables.this_file
if Models.is_modelled_for_nullability_as_internal po.pname then
" modelled in " ^ ModelTables.this_file
else ""
in
let description =

Loading…
Cancel
Save