[nullsafe][annotation graph] Don't fail while dealing with synthetic fields

Summary:
Sometimes there are annotations that don't correspond to the user facing
code.
Previously we would fail, now process them gracefully.

Reviewed By: artempyanykh

Differential Revision: D24890895

fbshipit-source-id: e64a866ec
master
Mitya Lyubarskiy 4 years ago committed by Facebook GitHub Bot
parent f2e3f67f40
commit cced510cb9

@ -99,10 +99,6 @@ let get_fix_annotation = function
let update_by_violation nodes provisional_violation =
let fix_annotation = get_fix_annotation provisional_violation in
Option.iter fix_annotation ~f:(fun annotation ->
if not (AnnotationMap.mem annotation nodes) then
Logging.die InternalError "Did not find a node for %a in the graph" ProvisionalAnnotation.pp
annotation ) ;
let offending_annotations = get_offending_annotations provisional_violation in
List.iter offending_annotations ~f:(fun annotation ->
match AnnotationMap.find_opt annotation nodes with
@ -112,17 +108,31 @@ let update_by_violation nodes provisional_violation =
(* If that provisional annotation becomes real [@Nullable], that would raise an issue fixable by the other annotation.
Add the new edge in the graph.
*)
annotation_point.dependent_points <-
List.dedup_and_sort
(fix_annotation :: annotation_point.dependent_points)
~compare:ProvisionalAnnotation.compare
if AnnotationMap.mem fix_annotation nodes then
annotation_point.dependent_points <-
List.dedup_and_sort
(fix_annotation :: annotation_point.dependent_points)
~compare:ProvisionalAnnotation.compare
else (
(* This is an edge case sitation. There is a corresponding ProvisionalAnnotation for this Java class, but
it is not in the list of the known provisional annotations for the class.
This can happen for e.g. syntethic fields / autogenerated code or other not yet supporte cases.
Conservatively record this situation as an unfixable violation.
*)
Logging.debug Analysis Medium
"Did not find a node for %a in the graph: recording a violation instead"
ProvisionalAnnotation.pp fix_annotation ;
annotation_point.num_violations <- annotation_point.num_violations + 1 )
| None ->
(* If that provisional annotation becomes real [@Nullable], that would lead to a violation
* (not related to other provisional annotations).
*)
annotation_point.num_violations <- annotation_point.num_violations + 1 )
| None ->
Logging.die InternalError "Did not find a node for %a in the graph"
(* This is not a real annotation point. This can happen for synthetic fields etc.
*)
Logging.debug Analysis Medium
"Did not find a node for %a in the graph: not processing this annotation"
ProvisionalAnnotation.pp annotation )

Loading…
Cancel
Save