From 7368039ba86ebbf11e1491872c3bdeed8a6df490 Mon Sep 17 00:00:00 2001 From: Mitya Lyubarskiy Date: Mon, 22 Jul 2019 02:36:43 -0700 Subject: [PATCH] [infer] Make infer respect external-packages param Summary: Fixes #1126 Different checks contain some ad hoc places that look at this param, but there is no systematic way to suppress this. The centralized place that is filtering results is `reporting.ml`. Note that this diff does not remove other usages, because they do more than mere filtering results. Reviewed By: jvillard Differential Revision: D16339655 fbshipit-source-id: afabdc97a --- infer/src/backend/reporting.ml | 10 +++++++++- infer/src/nullsafe/NullabilitySuggest.ml | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/infer/src/backend/reporting.ml b/infer/src/backend/reporting.ml index dea7f106a..6bc73950d 100644 --- a/infer/src/backend/reporting.ml +++ b/infer/src/backend/reporting.ml @@ -36,12 +36,20 @@ let log_issue_from_summary severity summary ~node ~session ~loc ~ltr ?extras exn | _ -> false in + let is_java_external_package = + match procname with + | Typ.Procname.Java java_pname -> + Typ.Procname.Java.is_external java_pname + | _ -> + false + in let should_suppress_lint = Language.curr_language_is Java && Annotations.ia_is_suppress_lint (Summary.get_attributes summary).ProcAttributes.method_annotation.return in - if should_suppress_lint || is_java_generated_method then () (* Skip the reporting *) + if should_suppress_lint || is_java_generated_method || is_java_external_package then () + (* Skip the reporting *) else let err_log = Summary.get_err_log summary in let clang_method_kind = Some attrs.clang_method_kind in diff --git a/infer/src/nullsafe/NullabilitySuggest.ml b/infer/src/nullsafe/NullabilitySuggest.ml index 97530c7ef..c76c9fa9e 100644 --- a/infer/src/nullsafe/NullabilitySuggest.ml +++ b/infer/src/nullsafe/NullabilitySuggest.ml @@ -188,7 +188,16 @@ let checker {Callbacks.summary; exe_env} = let report_access_path ap udchain = match AccessPath.get_field_and_annotation ap proc_data.tenv with | Some (field_name, _) when is_outside_codebase proc_name field_name -> - (* Skip reporting when the field is outside the analyzed codebase *) + (* Skip reporting when the field is outside the analyzed codebase. + Note that we do similar filtering on high level which is common + for all checkers. + But this one is different: here we look NOT at the function + to be reported (the one that is using the field), but the root + cause (the field with the wrong annotation itself). + NOTE: Ideally we'd like to support such filtering in the way that + is agnostic to particular checker, but it is not trivial to + do, so let's do it in ad hoc way. + *) () | Some (field_name, _) when Typ.Fieldname.Java.is_captured_parameter field_name -> (* Skip reporting when field comes from generated code *)