未验证 提交 77732c83 编写于 作者: S Skylot

fix(gui): ignore/limit waiting of canceled search task (#1568)

上级 a67fc839
......@@ -3,6 +3,7 @@ package jadx.gui.search;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
......@@ -65,6 +66,10 @@ public class SearchTask extends CancelableBackgroundTask {
}
public synchronized boolean addResult(JNode resultNode) {
if (isCanceled()) {
// ignore new results after cancel
return true;
}
this.results.accept(resultNode);
if (resultsLimit != 0 && resultsCount.incrementAndGet() >= resultsLimit) {
cancel();
......@@ -76,9 +81,9 @@ public class SearchTask extends CancelableBackgroundTask {
public synchronized void waitTask() {
if (future != null) {
try {
future.get();
future.get(2, TimeUnit.SECONDS);
} catch (Exception e) {
LOG.error("Wait search task failed", e);
LOG.warn("Wait search task failed", e);
} finally {
future.cancel(true);
future = null;
......
......@@ -406,7 +406,6 @@ public class SearchDialog extends CommonSearchDialog {
private synchronized void stopSearchTask() {
if (searchTask != null) {
searchTask.cancel();
searchTask.waitTask();
searchTask = null;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册