don't warn in cases where GuardedBy string is clearly unrecognizable

Reviewed By: peterogithub

Differential Revision: D3615388

fbshipit-source-id: 8deb7af
master
Sam Blackshear 9 years ago committed by Facebook Github Bot 3
parent e9aecd0afe
commit b500a5c4b5

@ -617,7 +617,14 @@ let prop_iter_add_hpred_footprint_to_prop pname tenv prop (lexp, typ) inst =
let add_guarded_by_constraints prop lexp pdesc =
let pname = Cfg.Procdesc.get_proc_name pdesc in
let excluded_guardedby_string str =
str = "ui_thread" in (* don't warn on @GuardedBy("ui_thread") *)
(* nothing with a space in it can be a valid Java expression, shouldn't warn *)
let is_invalid_exp_str str =
String.contains str ' ' in
(* don't warn on @GuardedBy("ui_thread") in any form *)
let is_ui_thread str =
let lowercase_str = String.lowercase str in
lowercase_str = "ui_thread" || lowercase_str = "ui-thread" || lowercase_str = "uithread" in
is_invalid_exp_str str || is_ui_thread str in
let guarded_by_str_is_this guarded_by_str =
string_is_suffix "this" guarded_by_str in
let guarded_by_str_is_class guarded_by_str class_str =

@ -49,9 +49,6 @@ public class GuardedByExample {
@GuardedBy("mReadWriteLock")
Object i = new Object();
@GuardedBy("ui_thread")
Object t = new Object();
private static Object sLock = new Object();
@GuardedBy("sLock")
@ -183,10 +180,6 @@ public class GuardedByExample {
}
}
void readTok() {
this.t.toString();
}
void readWriteLockOk() {
try (AutoCloseableReadWriteUpdateLock lock = mReadWriteLock) {
this.i.toString();
@ -293,6 +286,29 @@ public class GuardedByExample {
}
@GuardedBy("ui_thread")
Object uiThread1;
@GuardedBy("ui-thread")
Object uiThread2;
@GuardedBy("uithread")
Object uiThread3;
@GuardedBy("something that's clearly not an expression")
Object nonExpression;
// tests for not reporting false alarms on unrecognized GuardedBy strings
void accessUnrecognizedGuardedByFieldsOk() {
uiThread1 = new Object();
uiThread1.toString();
uiThread2 = new Object();
uiThread2.toString();
uiThread3 = new Object();
uiThread3.toString();
nonExpression = new Object();
nonExpression.toString();
}
// TODO: report on these cases
/*
public void unguardedCallSiteBad1() {

Loading…
Cancel
Save