diff --git a/infer/annotations/com/facebook/infer/annotation/ThreadConfined.java b/infer/annotations/com/facebook/infer/annotation/ThreadConfined.java index b7353864f..c3b3ff0c7 100644 --- a/infer/annotations/com/facebook/infer/annotation/ThreadConfined.java +++ b/infer/annotations/com/facebook/infer/annotation/ThreadConfined.java @@ -14,8 +14,17 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * This annotation tells the thread-safety analysis to assume that mutations in the annotated + * class/field/method are confined to the given thread name. For the thread name, you can either use + * the default constants UI/ANY or add your own. + */ @Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD }) @Retention(RetentionPolicy.CLASS) public @interface ThreadConfined { + String value(); /** the thread that the mutations should be confined to */ + public static String UI = "UI"; /** confined to the UI thread */ + public static String ANY = "ANY"; /** confined to any thread (but only that thread!) */ + } diff --git a/infer/tests/codetoanalyze/java/threadsafety/Annotations.java b/infer/tests/codetoanalyze/java/threadsafety/Annotations.java index 60a8848b4..aeb2dc8d2 100644 --- a/infer/tests/codetoanalyze/java/threadsafety/Annotations.java +++ b/infer/tests/codetoanalyze/java/threadsafety/Annotations.java @@ -87,7 +87,7 @@ class Annotations implements FunctionalInterface { con.x = 7; } - @ThreadConfined + @ThreadConfined(ThreadConfined.UI) class Confined { Integer x; @@ -100,7 +100,7 @@ class Annotations implements FunctionalInterface { Object fld; } - @ThreadConfined Obj encapsulatedField; + @ThreadConfined(ThreadConfined.ANY) Obj encapsulatedField; public void mutateConfinedFieldDirectlyOk() { this.encapsulatedField = new Obj(); @@ -114,7 +114,7 @@ class Annotations implements FunctionalInterface { this.encapsulatedField.fld = new Object(); } - @ThreadConfined + @ThreadConfined("some_custom_string") public void threadConfinedMethodOk() { this.f = new Object(); }