You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
7 years ago
|
/*
|
||
6 years ago
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
7 years ago
|
*
|
||
7 years ago
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
7 years ago
|
*/
|
||
|
|
||
|
import android.support.annotation.UiThread;
|
||
6 years ago
|
import java.util.concurrent.CountDownLatch;
|
||
|
import java.util.concurrent.ExecutionException;
|
||
|
import java.util.concurrent.Future;
|
||
7 years ago
|
|
||
|
class Dedup {
|
||
|
CountDownLatch latch;
|
||
7 years ago
|
Future future;
|
||
7 years ago
|
|
||
|
// only one report should be seen
|
||
|
@UiThread
|
||
7 years ago
|
void onUiThreadBad() throws InterruptedException, ExecutionException {
|
||
7 years ago
|
callMethodWithMultipleBlocksBad();
|
||
|
}
|
||
|
|
||
|
// three reports are expected
|
||
|
@UiThread
|
||
7 years ago
|
void callMethodWithMultipleBlocksBad() throws InterruptedException, ExecutionException {
|
||
|
future.get();
|
||
7 years ago
|
latch.await();
|
||
7 years ago
|
future.get();
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
|
Object lockA, lockB;
|
||
|
|
||
|
// deadlock should be reported between oneWayBad and anotherWayBad only
|
||
|
void oneWayBad() {
|
||
6 years ago
|
synchronized (lockA) {
|
||
|
synchronized (lockB) {
|
||
|
}
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void anotherWayBad() {
|
||
6 years ago
|
synchronized (lockB) {
|
||
|
synchronized (lockA) {
|
||
|
}
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// this is creating a longer trace than anotherWayBad, so should be suppressed
|
||
|
void thirdLongerWayBad() {
|
||
|
anotherWayBad();
|
||
|
}
|
||
7 years ago
|
}
|