[thread-safety] handle some annotations as aliases of ThreadConfined

Reviewed By: jaegs

Differential Revision: D4458676

fbshipit-source-id: da42ad5
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent 369feb4149
commit b227ee58a6

@ -426,10 +426,16 @@ let is_thread_confined_method tenv pdesc =
(* 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 annotated with @UiThread or @OnEvent(SomeEvent.class) always run on the UI
thread *)
(* assume that methods annotated with @UiThread, @OnEvent, @OnBind, @OnMount, @OnUnbind,
@OnUnmount always run on the UI thread *)
is_annotated
(fun annot -> Annotations.ia_is_ui_thread annot || Annotations.ia_is_on_event annot)
(fun annot -> Annotations.ia_is_ui_thread annot ||
Annotations.ia_is_on_bind annot ||
Annotations.ia_is_on_event annot ||
Annotations.ia_is_on_mount annot ||
Annotations.ia_is_on_unbind annot ||
Annotations.ia_is_on_unmount annot)
proc_desc
let is_assumed_thread_safe pdesc =

@ -103,6 +103,9 @@ let nullable = "Nullable"
let nonnull = "Nonnull"
let on_bind = "OnBind"
let on_event = "OnEvent"
let on_mount = "OnMount"
let on_unbind = "OnUnbind"
let on_unmount = "OnUnmount"
let camel_nonnull = "NonNull"
let notnull = "NotNull"
let present = "Present"
@ -224,6 +227,18 @@ let ia_is_suppress_lint ia =
let ia_is_on_event ia =
ia_ends_with ia on_event
let ia_is_on_bind ia =
ia_ends_with ia on_bind
let ia_is_on_mount ia =
ia_ends_with ia on_mount
let ia_is_on_unbind ia =
ia_ends_with ia on_unbind
let ia_is_on_unmount ia =
ia_ends_with ia on_unmount
let ia_is_privacy_source ia =
ia_ends_with ia privacy_source

@ -94,6 +94,10 @@ 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_on_bind : Annot.Item.t -> bool
val ia_is_on_mount : Annot.Item.t -> bool
val ia_is_on_unbind : Annot.Item.t -> bool
val ia_is_on_unmount : 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

@ -23,11 +23,31 @@ 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 OnBind {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
@interface OnEvent {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
@interface OnMount {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
@interface OnUnbind {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
@interface OnUnmount {
}
@ThreadSafe
class Annotations {
Object f;
@ -89,6 +109,26 @@ class Annotations {
this.f = new Object();
}
@OnBind
public void onBindMethodOk() {
this.f = new Object();
}
@OnMount
public void onMountMethodOk() {
this.f = new Object();
}
@OnUnmount
public void onUnmountMethodOk() {
this.f = new Object();
}
@OnUnbind
public void onUnbindMethodOk() {
this.f = new Object();
}
@AssumeThreadSafe(because = "it's a test")
public void assumeThreadSafeOk() {
this.f = new Object();

Loading…
Cancel
Save