From 1e3fafb558f161e9a538174a57f6f102ff3e706a Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 23 Apr 2019 02:53:07 -0700 Subject: [PATCH] [report] avoid embarrassing "object `null` could be null" message Summary: A long-standing easter egg from infer error messages is the "object `null` could be null and is dereferenced at line ...". I tried to fix this but the part that generates the first "null" in the message and the part that generates the second one are very far apart and it's hard to see how to make the second part aware of the first in a clean way. Instead, hack around it by detecting if the string representing the value is literally `null` and in that case chop `could be null ` from the error messages... Reviewed By: jeremydubreil Differential Revision: D14972324 fbshipit-source-id: ccc48ce6b --- infer/src/IR/Localise.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/infer/src/IR/Localise.ml b/infer/src/IR/Localise.ml index 33ceca8a4d8..3aaaf6b5ff3 100644 --- a/infer/src/IR/Localise.ml +++ b/infer/src/IR/Localise.ml @@ -180,9 +180,11 @@ let deref_str_null_ proc_name_opt problem_str_ = {tags= Tags.create (); value_pre= Some (pointer_or_object ()); value_post= None; problem_str} +let could_be_null_and_prefix = "could be null and " + (** dereference strings for null dereference *) let deref_str_null proc_name_opt = - let problem_str = "could be null and is dereferenced" in + let problem_str = could_be_null_and_prefix ^ "is dereferenced" in deref_str_null_ proc_name_opt problem_str @@ -412,7 +414,11 @@ let dereference_string proc_name deref_str value_str access_opt loc = ^ MF.monospaced_to_string weak_var_str ^ ", a weak pointer captured in the block, and is dereferenced without a null check" | None, None -> - deref_str.problem_str + (* hack to avoid dumb message "null could be null" *) + if String.equal value_str "null" then + String.chop_prefix deref_str.problem_str ~prefix:could_be_null_and_prefix + |> Option.value ~default:deref_str.problem_str + else deref_str.problem_str in [problem_str ^ " " ^ at_line tags loc] in