diff --git a/infer/src/backend/rearrange.ml b/infer/src/backend/rearrange.ml index f9aef8ead..015162294 100644 --- a/infer/src/backend/rearrange.ml +++ b/infer/src/backend/rearrange.ml @@ -604,14 +604,18 @@ let prop_iter_add_hpred_footprint_to_prop pname tenv prop (lexp, typ) inst = (** If [lexp] is an access to a field that is annotated with @GuardedBy, add constraints to [prop] expressing the safety conditions for the access. Complain if these conditions cannot be met. *) let add_guarded_by_constraints prop lexp pdesc = + let excluded_guardedby_string str = + str = "ui_thread" in (* don't warn on @GuardedBy("ui_thread") *) let sigma = Prop.get_sigma prop in let extract_guarded_by_str item_annot = let annot_extract_guarded_by_str (annot, _) = if Annotations.annot_ends_with annot Annotations.guarded_by then match annot.Sil.parameters with - | [guarded_by_str] -> Some guarded_by_str - | _ -> None + | [guarded_by_str] when not (excluded_guardedby_string guarded_by_str) -> + Some guarded_by_str + | _ -> + None else None in IList.find_map_opt annot_extract_guarded_by_str item_annot in diff --git a/infer/tests/codetoanalyze/java/infer/GuardedByExample.java b/infer/tests/codetoanalyze/java/infer/GuardedByExample.java index bf6c4ca55..5a33e861e 100644 --- a/infer/tests/codetoanalyze/java/infer/GuardedByExample.java +++ b/infer/tests/codetoanalyze/java/infer/GuardedByExample.java @@ -37,6 +37,10 @@ public class GuardedByExample { @GuardedBy("SomeLockThatDoesntExist") Object h = new Object(); + @GuardedBy("ui_thread") + Object t = new Object(); + + void readFBad() { this.f.toString(); } @@ -120,6 +124,10 @@ public class GuardedByExample { } } + void readTok() { + this.t.toString(); + } + // TODO: report on these cases /* public void unguardedCallSiteBad1() {