[nullsafe] Add an option to warn about unvetted third party in default mode

Summary:
Currently, we don't issue warnings for third party return value in
non-@Nullsafe modes.

For some integrations, this feature is useful.

This diff repurposes the existing param to suit this goal.

Reviewed By: artempyanykh

Differential Revision: D25186043

fbshipit-source-id: 308101841
master
Mitya Lyubarskiy 4 years ago committed by Facebook GitHub Bot
parent c6a33c88b7
commit 7dcbacf693

@ -1667,11 +1667,12 @@ INTERNAL OPTIONS
This feature is needed for compatibility reasons. (Conversely:
--no-nullsafe-disable-field-not-initialized-in-nonstrict-classes)
--no-nullsafe-optimistic-third-party-params-in-non-strict
Deactivates: Nullsafe: in this mode we treat non annotated third
party method params as if they were annotated as nullable.
(Conversely:
--nullsafe-optimistic-third-party-params-in-non-strict)
--no-nullsafe-optimistic-third-party-in-default-mode
Deactivates: Nullsafe: Unless @Nullsafe annotation is used, treat
not annotated third party method params as if they were annotated
as nullable, and return values as if they were annotated as
non-null (Conversely:
--nullsafe-optimistic-third-party-in-default-mode)
--nullsafe-strict-containers
Activates: Warn when containers are used with nullable keys or

@ -1650,17 +1650,15 @@ and nullsafe_disable_field_not_initialized_in_nonstrict_classes =
marked as @NullsafeStrict. This feature is needed for compatibility reasons."
and nullsafe_optimistic_third_party_params_in_non_strict =
and nullsafe_optimistic_third_party_in_default_mode =
CLOpt.mk_bool
~long:
"nullsafe-optimistic-third-party-params-in-non-strict"
(* Turned on for compatibility reasons.
Historically this is because there was no actionable way to change third party annotations.
Now that we have such a support, this behavior should be reconsidered, provided
our tooling and error reporting is friendly enough to be smoothly used by developers.
*) ~default:true
"Nullsafe: in this mode we treat non annotated third party method params as if they were \
annotated as nullable."
"nullsafe-optimistic-third-party-in-default-mode"
(* Turned on for compatibility reasons
*) ~default:true
"Nullsafe: Unless @Nullsafe annotation is used, treat not annotated third party method params \
as if they were annotated as nullable, and return values as if they were annotated as \
non-null"
and nullsafe_third_party_signatures =
@ -2996,8 +2994,8 @@ and nullsafe_disable_field_not_initialized_in_nonstrict_classes =
!nullsafe_disable_field_not_initialized_in_nonstrict_classes
and nullsafe_optimistic_third_party_params_in_non_strict =
!nullsafe_optimistic_third_party_params_in_non_strict
and nullsafe_optimistic_third_party_in_default_mode =
!nullsafe_optimistic_third_party_in_default_mode
and nullsafe_third_party_signatures = !nullsafe_third_party_signatures

@ -401,7 +401,7 @@ val nullsafe_annotation_graph : bool
val nullsafe_disable_field_not_initialized_in_nonstrict_classes : bool
val nullsafe_optimistic_third_party_params_in_non_strict : bool
val nullsafe_optimistic_third_party_in_default_mode : bool
val nullsafe_third_party_signatures : string option

@ -49,8 +49,9 @@ module ReportableViolation = struct
let from nullsafe_mode ({lhs; rhs} as violation) =
let falls_under_optimistic_third_party =
Config.nullsafe_optimistic_third_party_params_in_non_strict
Config.nullsafe_optimistic_third_party_in_default_mode
&& NullsafeMode.equal nullsafe_mode Default
(* Treat third party params as if they were [@Nullable] *)
&& Nullability.equal (AnnotatedNullability.get_nullability lhs) ThirdPartyNonnull
in
let is_non_reportable =

@ -150,12 +150,8 @@ let mk_recommendation_for_third_party_field nullsafe_mode field =
match nullsafe_mode with
| NullsafeMode.Strict ->
F.sprintf "access %s via a nullsafe strict getter" field
| NullsafeMode.Local _ ->
| NullsafeMode.Local _ | NullsafeMode.Default ->
F.sprintf "access %s via a nullsafe getter" field
| NullsafeMode.Default ->
Logging.die InternalError
"mk_recommendation_for_third_party_field:: Should not happen: we should tolerate third \
party in default mode"
let get_info object_origin nullsafe_mode untrusted_kind =

@ -68,8 +68,10 @@ let is_considered_nonnull ~nullsafe_mode nullability =
| NullsafeMode.Local NullsafeMode.Trust.All ->
UncheckedNonnull
| NullsafeMode.Default ->
(* In default mode, we trust everything, even not annotated third party. *)
ThirdPartyNonnull
(* We trust all internal method declarations, and, if specified separately,
even not annotated third party. *)
if Config.nullsafe_optimistic_third_party_in_default_mode then ThirdPartyNonnull
else UncheckedNonnull
in
is_subtype ~subtype:nullability ~supertype:least_required

Loading…
Cancel
Save