[nullsafe] Don't emit Field Not Initialized warnings on @JsonField-annotated fields

Summary: Per title

Reviewed By: artempyanykh

Differential Revision: D19949608

fbshipit-source-id: ca230a0cd
master
Mitya Lyubarskiy 5 years ago committed by Facebook Github Bot
parent 175af05b8b
commit 8ab9a7e14e

@ -51,6 +51,8 @@ let inject_prop = "InjectProp"
let inject_view = "InjectView" let inject_view = "InjectView"
let json_field = "JsonField"
let lockless = "Lockless" let lockless = "Lockless"
let nonnull = "Nonnull" let nonnull = "Nonnull"
@ -241,6 +243,8 @@ let ia_is_ignore_allocations ia = ia_ends_with ia ignore_allocations
let ia_is_inject ia = ia_ends_with ia inject let ia_is_inject ia = ia_ends_with ia inject
let ia_is_json_field ia = ia_ends_with ia json_field
let ia_is_suppress_lint ia = ia_ends_with ia suppress_lint let ia_is_suppress_lint ia = ia_ends_with ia suppress_lint
let ia_is_thread_confined ia = ia_ends_with ia thread_confined let ia_is_thread_confined ia = ia_ends_with ia thread_confined

@ -90,6 +90,8 @@ val ia_is_ignore_allocations : Annot.Item.t -> bool
val ia_is_inject : Annot.Item.t -> bool val ia_is_inject : Annot.Item.t -> bool
val ia_is_json_field : Annot.Item.t -> bool
val ia_is_suppress_lint : Annot.Item.t -> bool val ia_is_suppress_lint : Annot.Item.t -> bool
val ia_is_not_thread_safe : Annot.Item.t -> bool val ia_is_not_thread_safe : Annot.Item.t -> bool

@ -251,12 +251,15 @@ let check_constructor_initialization tenv find_canonical_duplicate curr_construc
| Some {fields} -> | Some {fields} ->
let do_field (field_name, field_type, _) = let do_field (field_name, field_type, _) =
let annotated_field = AnnotatedField.get tenv field_name ts in let annotated_field = AnnotatedField.get tenv field_name ts in
let is_injector_readonly_annotated = let is_initialized_by_framework =
match annotated_field with match annotated_field with
| None -> | None ->
false false
| Some {annotation_deprecated} -> | Some {annotation_deprecated} ->
(* Initialized by Dependency Injection framework *)
Annotations.ia_is_field_injector_readonly annotation_deprecated Annotations.ia_is_field_injector_readonly annotation_deprecated
(* Initialized by Json framework *)
|| Annotations.ia_is_json_field annotation_deprecated
in in
let is_initialized_in_either_constructor_or_initializer = let is_initialized_in_either_constructor_or_initializer =
let is_initialized = function let is_initialized = function
@ -287,7 +290,10 @@ let check_constructor_initialization tenv find_canonical_duplicate curr_construc
let fld_cname = Fieldname.get_class_name field_name in let fld_cname = Fieldname.get_class_name field_name in
Typ.Name.equal name fld_cname Typ.Name.equal name fld_cname
in in
(not is_injector_readonly_annotated) (* various frameworks initialize spefic fields behind the scenes,
we assume they are doing it well
*)
(not is_initialized_by_framework)
(* primitive types can not be null so initialization check is not needed *) (* primitive types can not be null so initialization check is not needed *)
&& PatternMatch.type_is_class field_type && PatternMatch.type_is_class field_type
&& in_current_class && in_current_class

Loading…
Cancel
Save