[thread-safety] suppress warnings on methods annotated with @OnEvent

Reviewed By: peterogithub

Differential Revision: D4407224

fbshipit-source-id: 511aad4
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent cece221ab7
commit 1891a16f8f

@ -300,15 +300,13 @@ let is_thread_confined_method tenv pname =
(* we don't want to warn on methods that run on the UI thread because they should always be
single-threaded *)
let runs_on_ui_thread proc_desc =
(* assume that methods named onClick always run on the UI thread *)
let is_on_click pdesc = match Procdesc.get_proc_name pdesc with
| Procname.Java java_pname -> Procname.java_get_method java_pname = "onClick"
| _ -> false in
(* assume that methods annotated with @UiThread or @OnEvent(SomeEvent.class) always run on the UI
thread *)
let is_annotated pdesc =
let annotated_signature = Annotations.get_annotated_signature (Procdesc.get_attributes pdesc) in
let ret_annotation, _ = annotated_signature.Annotations.ret in
Annotations.ia_is_ui_thread ret_annotation in
is_on_click proc_desc || is_annotated proc_desc
Annotations.ia_is_ui_thread ret_annotation || Annotations.ia_is_on_event ret_annotation in
is_annotated proc_desc
(* return true if we should compute a summary for the procedure. if this returns false, we won't
analyze the procedure or report any warnings on it *)

@ -102,6 +102,7 @@ let mutable_ = "Mutable"
let nullable = "Nullable"
let nonnull = "Nonnull"
let on_bind = "OnBind"
let on_event = "OnEvent"
let camel_nonnull = "NonNull"
let notnull = "NotNull"
let present = "Present"
@ -208,6 +209,9 @@ let ia_is_ignore_allocations ia =
let ia_is_suppress_lint ia =
ia_ends_with ia suppress_lint
let ia_is_on_event ia =
ia_ends_with ia on_event
let ia_is_privacy_source ia =
ia_ends_with ia privacy_source

@ -93,6 +93,7 @@ val ia_is_performance_critical : Annot.Item.t -> bool
val ia_is_no_allocation : Annot.Item.t -> bool
val ia_is_ignore_allocations : Annot.Item.t -> bool
val ia_is_suppress_lint : Annot.Item.t -> bool
val ia_is_on_event : Annot.Item.t -> bool
val ia_is_privacy_source : Annot.Item.t -> bool
val ia_is_privacy_sink : Annot.Item.t -> bool
val ia_is_integrity_source : Annot.Item.t -> bool

@ -9,12 +9,22 @@
package codetoanalyze.java.checkers;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import android.support.annotation.UiThread;
import com.facebook.infer.annotation.ThreadConfined;
/** tests for classes and method annotations that are meaningful w.r.t thread-safety */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
@interface OnEvent {
}
@ThreadSafe
class Annotations {
Object f;
@ -32,7 +42,8 @@ class Annotations {
this.f = new Object();
}
// we model onClick as running on the UI thread, should not warn
// anything annotated with OnEvent is modeled as running on the UI thread, should not warn
@OnEvent
public void onClick() {
this.f = new Object();
}

Loading…
Cancel
Save