Skip to content

Commit

Permalink
fix(gui): resolve various minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Jun 20, 2022
1 parent 4679172 commit 8486891
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
7 changes: 4 additions & 3 deletions jadx-gui/src/main/java/jadx/gui/jobs/BackgroundExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ protected TaskStatus doInBackground() throws Exception {
task.onDone(this);
// treat UI task operations as part of the task to not mix with others
UiUtils.uiRunAndWait(() -> {
progressPane.setVisible(false);
task.onFinish(this);
progressPane.setVisible(false);
});
} finally {
taskComplete(id);
progressPane.changeVisibility(this, false);
}
}
return status;
Expand Down Expand Up @@ -230,13 +231,13 @@ private void performCancel(ThreadPoolExecutor executor) throws InterruptedExcept
// force termination
task.cancel();
executor.shutdown();
if (executor.awaitTermination(5, TimeUnit.SECONDS)) {
if (executor.awaitTermination(2, TimeUnit.SECONDS)) {
LOG.debug("Task cancel complete");
return;
}
LOG.debug("Forcing tasks cancel");
executor.shutdownNow();
boolean complete = executor.awaitTermination(30, TimeUnit.SECONDS);
boolean complete = executor.awaitTermination(5, TimeUnit.SECONDS);
LOG.debug("Forced task cancel status: {}",
complete ? "success" : "fail, still active: " + executor.getActiveCount());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,21 @@ public JClass getJClass() {
return null;
}

public boolean isDisposed() {
return node == null;
}

public void dispose() {
// code area reference can still be used somewhere in UI objects,
// reset node reference to allow to GC jadx objects tree
node = null;
contentPanel = null;

// also clear internals
setIgnoreRepaint(true);
setText("");
setEnabled(false);
setSyntaxEditingStyle(SYNTAX_STYLE_NONE);
setLinkGenerator(null);
for (MouseListener mouseListener : getMouseListeners()) {
removeMouseListener(mouseListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,15 @@ public void restoreEditorViewState(EditorViewState viewState) {
} catch (Exception e) {
LOG.debug("Failed to restore view position: {}", viewState.getViewPoint(), e);
}
int caretPos = viewState.getCaretPos();
try {
activePanel.getCodeArea().setCaretPosition(viewState.getCaretPos());
AbstractCodeArea codeArea = activePanel.getCodeArea();
int codeLen = codeArea.getDocument().getLength();
if (caretPos >= 0 && caretPos < codeLen) {
codeArea.setCaretPosition(caretPos);
}
} catch (Exception e) {
LOG.debug("Failed to restore caret position: {}", viewState.getCaretPos(), e);
LOG.debug("Failed to restore caret position: {}", caretPos, e);
}
}

Expand Down
4 changes: 4 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ private void navToDecl(Point point, CodeLinkGenerator codeLinkGenerator) {
@Override
public ICodeInfo getCodeInfo() {
if (cachedCodeInfo == null) {
if (isDisposed()) {
LOG.debug("CodeArea used after dispose!");
return ICodeInfo.EMPTY;
}
cachedCodeInfo = Objects.requireNonNull(node.getCodeInfo());
}
return cachedCodeInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ public JadxTokenMaker(CodeArea codeArea) {

@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
if (codeArea.isDisposed()) {
return new TokenImpl();
}
try {
Token tokens = super.getTokenList(text, initialTokenType, startOffset);
if (tokens.getType() != TokenTypes.NULL) {
if (tokens != null && tokens.getType() != TokenTypes.NULL) {
processTokens(tokens);
}
return tokens;
Expand Down

0 comments on commit 8486891

Please sign in to comment.