Summary: Introduce an annotation that forces the summary of a method to be free of blocking events, without suppressing other reports. Reviewed By: jeremydubreil Differential Revision: D8276787 fbshipit-source-id: be9eed8master
parent
0da5435d9d
commit
4820e3db1e
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2004-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.infer.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({
|
||||
ElementType.CONSTRUCTOR,
|
||||
ElementType.METHOD,
|
||||
ElementType.TYPE
|
||||
})
|
||||
|
||||
// Signal to the starvation checker that the method (or all the methods of the class,
|
||||
// if at class level) does not perform any potentially blocking operations. Can be used to
|
||||
// effectively filter out all method calls which Infer may consider blocking. This means that
|
||||
// not only Infer will not warn on any starvation issues in the method, but will also not warn on
|
||||
// any of the callers of this method.
|
||||
public @interface NonBlocking {}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.io.IOException;
|
||||
import android.support.annotation.UiThread;
|
||||
import com.facebook.infer.annotation.NonBlocking;
|
||||
|
||||
class NonBlk {
|
||||
Future future;
|
||||
|
||||
@NonBlocking
|
||||
void doGet() throws InterruptedException, ExecutionException {
|
||||
future.get();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void onUiThreadIndirectOk() throws InterruptedException, ExecutionException {
|
||||
doGet();
|
||||
}
|
||||
|
||||
@NonBlocking
|
||||
@UiThread
|
||||
void onUiThreadDirectOk() throws InterruptedException, ExecutionException {
|
||||
future.get();
|
||||
}
|
||||
|
||||
@NonBlocking
|
||||
synchronized void deadlockABBad() {
|
||||
synchronized(future) {}
|
||||
}
|
||||
|
||||
@NonBlocking
|
||||
void deadlockBABad() {
|
||||
synchronized(future) {
|
||||
synchronized(this) {}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue