Skip to content

Commit

Permalink
fix(gui): ignore/limit waiting of canceled search task (#1568)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Jul 1, 2022
1 parent a67fc83 commit 77732c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 7 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/search/SearchTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -65,6 +66,10 @@ public synchronized void fetchResults() {
}

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();
Expand All @@ -76,9 +81,9 @@ public synchronized boolean addResult(JNode resultNode) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ private boolean buildSearch(String text, SearchSettings searchSettings) {
private synchronized void stopSearchTask() {
if (searchTask != null) {
searchTask.cancel();
searchTask.waitTask();
searchTask = null;
}
}
Expand Down

0 comments on commit 77732c8

Please sign in to comment.