From 987347ceca51a707054bc4ece38d312df856434a Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Wed, 28 Jun 2017 17:12:04 -0700 Subject: [PATCH] [infer][java] Infer should not suggest to add @Nullable for the field nullified on Fragement onDestroyView Reviewed By: grievejia Differential Revision: D5342213 fbshipit-source-id: 0213578 --- infer/src/checkers/NullabilitySuggest.ml | 27 +++++++++++-------- .../codetoanalyze/java/checkers/issues.exp | 4 --- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/infer/src/checkers/NullabilitySuggest.ml b/infer/src/checkers/NullabilitySuggest.ml index da7c0da71..d70729eaa 100644 --- a/infer/src/checkers/NullabilitySuggest.ml +++ b/infer/src/checkers/NullabilitySuggest.ml @@ -178,14 +178,19 @@ let checker { Callbacks.summary; proc_desc; tenv; } = in Domain.iter report_access_path astate in - (* Assume all fields are not null in the beginning *) - let initial = Domain.empty, IdAccessPathMapDomain.empty in - let proc_data = ProcData.make_default proc_desc tenv in - match Analyzer.compute_post proc_data ~initial ~debug:false with - | Some (post, _) -> - report post proc_data; - summary - | None -> - failwithf - "Analyzer failed to compute post for %a" - Typ.Procname.pp (Procdesc.get_proc_name proc_data.pdesc) + let proc_name = Procdesc.get_proc_name proc_desc in + if AndroidFramework.is_destroy_method proc_name then + (* Skip the fields nullified in Fragment onDestroy and onDestroyView *) + summary + else + (* Assume all fields are not null in the beginning *) + let initial = Domain.empty, IdAccessPathMapDomain.empty in + let proc_data = ProcData.make_default proc_desc tenv in + match Analyzer.compute_post proc_data ~initial ~debug:false with + | Some (post, _) -> + report post proc_data; + summary + | None -> + failwithf + "Analyzer failed to compute post for %a" + Typ.Procname.pp proc_name diff --git a/infer/tests/codetoanalyze/java/checkers/issues.exp b/infer/tests/codetoanalyze/java/checkers/issues.exp index 3d023fa3f..a61115c81 100644 --- a/infer/tests/codetoanalyze/java/checkers/issues.exp +++ b/infer/tests/codetoanalyze/java/checkers/issues.exp @@ -26,10 +26,6 @@ codetoanalyze/java/checkers/ExpensiveInheritanceExample.java, void ExpensiveInhe codetoanalyze/java/checkers/ExpensiveInheritanceExample.java, void ExpensiveInheritanceExample.reportsBecauseFooIsExpensiveInA(A), 1, CHECKERS_CALLS_EXPENSIVE_METHOD, [] codetoanalyze/java/checkers/ExpensiveInterfaceExample.java, void ExpensiveInterfaceExample$ImplementsInterface.m1(), 1, CHECKERS_CALLS_EXPENSIVE_METHOD, [] codetoanalyze/java/checkers/ExpensiveSubtypingExample.java, void ExpensiveSubtypingExample.m3(), 0, CHECKERS_EXPENSIVE_OVERRIDES_UNANNOTATED, [return from a call to void ExpensiveSubtypingExample.m3()] -codetoanalyze/java/checkers/FragmentDoesNotRetainViewExample.java, void FragmentDoesNotRetainViewExample.onDestroyView(), 1, FIELD_SHOULD_BE_NULLABLE, [Field mView1 is assigned null here] -codetoanalyze/java/checkers/FragmentDoesNotRetainViewExample.java, void FragmentDoesNotRetainViewExample.onDestroyView(), 3, FIELD_SHOULD_BE_NULLABLE, [Field mView2 is assigned null here] -codetoanalyze/java/checkers/FragmentDoesNotRetainViewExample.java, void FragmentDoesNotRetainViewExample.onDestroyView(), 5, FIELD_SHOULD_BE_NULLABLE, [Field mCustomView is assigned null here] -codetoanalyze/java/checkers/FragmentDoesNotRetainViewExample.java, void FragmentDoesNotRetainViewExample.onDestroyView(), 6, FIELD_SHOULD_BE_NULLABLE, [Field mViewSubclass is assigned null here] codetoanalyze/java/checkers/FragmentRetainsViewExample.java, void FragmentRetainsViewExample.onDestroyView(), 0, CHECKERS_FRAGMENT_RETAINS_VIEW, [return from a call to void FragmentRetainsViewExample.onDestroyView()] codetoanalyze/java/checkers/FragmentRetainsViewExample.java, void FragmentRetainsViewExample.onDestroyView(), 0, CHECKERS_FRAGMENT_RETAINS_VIEW, [return from a call to void FragmentRetainsViewExample.onDestroyView()] codetoanalyze/java/checkers/FragmentRetainsViewExample.java, void FragmentRetainsViewExample.onDestroyView(), 0, CHECKERS_FRAGMENT_RETAINS_VIEW, [return from a call to void FragmentRetainsViewExample.onDestroyView()]