diff --git a/infer/src/checkers/annotations.ml b/infer/src/checkers/annotations.ml index ee6ec80ef..2da68e88b 100644 --- a/infer/src/checkers/annotations.ml +++ b/infer/src/checkers/annotations.ml @@ -51,6 +51,8 @@ let inject_prop = "InjectProp" let inject_view = "InjectView" +let json_field = "JsonField" + let lockless = "Lockless" 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_json_field ia = ia_ends_with ia json_field + let ia_is_suppress_lint ia = ia_ends_with ia suppress_lint let ia_is_thread_confined ia = ia_ends_with ia thread_confined diff --git a/infer/src/checkers/annotations.mli b/infer/src/checkers/annotations.mli index 5335e038d..ec20f9006 100644 --- a/infer/src/checkers/annotations.mli +++ b/infer/src/checkers/annotations.mli @@ -90,6 +90,8 @@ val ia_is_ignore_allocations : 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_not_thread_safe : Annot.Item.t -> bool diff --git a/infer/src/nullsafe/eradicateChecks.ml b/infer/src/nullsafe/eradicateChecks.ml index d1133e100..2b5aa4998 100644 --- a/infer/src/nullsafe/eradicateChecks.ml +++ b/infer/src/nullsafe/eradicateChecks.ml @@ -251,12 +251,15 @@ let check_constructor_initialization tenv find_canonical_duplicate curr_construc | Some {fields} -> let do_field (field_name, field_type, _) = let annotated_field = AnnotatedField.get tenv field_name ts in - let is_injector_readonly_annotated = + let is_initialized_by_framework = match annotated_field with | None -> false | Some {annotation_deprecated} -> + (* Initialized by Dependency Injection framework *) Annotations.ia_is_field_injector_readonly annotation_deprecated + (* Initialized by Json framework *) + || Annotations.ia_is_json_field annotation_deprecated in let is_initialized_in_either_constructor_or_initializer = 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 Typ.Name.equal name fld_cname 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 *) && PatternMatch.type_is_class field_type && in_current_class