From cced510cb99d5746796f3bc526cad6b49ba2f156 Mon Sep 17 00:00:00 2001 From: Mitya Lyubarskiy Date: Mon, 16 Nov 2020 09:41:45 -0800 Subject: [PATCH] [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 --- infer/src/nullsafe/AnnotationGraph.ml | 28 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/infer/src/nullsafe/AnnotationGraph.ml b/infer/src/nullsafe/AnnotationGraph.ml index 2ad12d229..063344367 100644 --- a/infer/src/nullsafe/AnnotationGraph.ml +++ b/infer/src/nullsafe/AnnotationGraph.ml @@ -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 )