Skip to content

Commit

Permalink
[report] avoid embarrassing "object null could be null" message
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jvillard authored and facebook-github-bot committed Apr 23, 2019
1 parent 95132bc commit 1e3fafb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions infer/src/IR/Localise.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1e3fafb

Please sign in to comment.