From d972d9ec742ec684268a8b9d8171ca7694c86458 Mon Sep 17 00:00:00 2001 From: Skylot Date: Tue, 28 Jun 2022 16:20:31 +0100 Subject: [PATCH] fix(gui): ignore errors on code area dispose (#1545) --- .../gui/ui/codearea/AbstractCodeArea.java | 46 ++++++++++--------- .../java/jadx/gui/ui/codearea/SmaliArea.java | 4 +- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/jadx-gui/src/main/java/jadx/gui/ui/codearea/AbstractCodeArea.java b/jadx-gui/src/main/java/jadx/gui/ui/codearea/AbstractCodeArea.java index 2ddff1f1fa3..8283e64c942 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/codearea/AbstractCodeArea.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/codearea/AbstractCodeArea.java @@ -367,29 +367,33 @@ public void dispose() { contentPanel = null; // also clear internals - setIgnoreRepaint(true); - setText(""); - setEnabled(false); - setSyntaxEditingStyle(SYNTAX_STYLE_NONE); - setLinkGenerator(null); - for (MouseListener mouseListener : getMouseListeners()) { - removeMouseListener(mouseListener); - } - for (MouseMotionListener mouseMotionListener : getMouseMotionListeners()) { - removeMouseMotionListener(mouseMotionListener); - } - JPopupMenu popupMenu = getPopupMenu(); - for (PopupMenuListener popupMenuListener : popupMenu.getPopupMenuListeners()) { - popupMenu.removePopupMenuListener(popupMenuListener); - } - for (Component component : popupMenu.getComponents()) { - if (component instanceof JMenuItem) { - Action action = ((JMenuItem) component).getAction(); - if (action instanceof JNodeAction) { - ((JNodeAction) action).dispose(); + try { + setIgnoreRepaint(true); + setText(""); + setEnabled(false); + setSyntaxEditingStyle(SYNTAX_STYLE_NONE); + setLinkGenerator(null); + for (MouseListener mouseListener : getMouseListeners()) { + removeMouseListener(mouseListener); + } + for (MouseMotionListener mouseMotionListener : getMouseMotionListeners()) { + removeMouseMotionListener(mouseMotionListener); + } + JPopupMenu popupMenu = getPopupMenu(); + for (PopupMenuListener popupMenuListener : popupMenu.getPopupMenuListeners()) { + popupMenu.removePopupMenuListener(popupMenuListener); + } + for (Component component : popupMenu.getComponents()) { + if (component instanceof JMenuItem) { + Action action = ((JMenuItem) component).getAction(); + if (action instanceof JNodeAction) { + ((JNodeAction) action).dispose(); + } } } + popupMenu.removeAll(); + } catch (Throwable e) { + LOG.debug("Error on code area dispose", e); } - popupMenu.removeAll(); } } diff --git a/jadx-gui/src/main/java/jadx/gui/ui/codearea/SmaliArea.java b/jadx-gui/src/main/java/jadx/gui/ui/codearea/SmaliArea.java index d20efaf4c59..0135f3919b3 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/codearea/SmaliArea.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/codearea/SmaliArea.java @@ -136,7 +136,7 @@ public void scrollToDebugPos(int pos) { @Override public Font getFont() { - if (model == null) { + if (model == null || isDisposed()) { return super.getFont(); } return model.getFont(); @@ -144,7 +144,7 @@ public Font getFont() { @Override public Font getFontForTokenType(int type) { - return model.getFont(); + return getFont(); } private boolean shouldUseSmaliPrinterV2() {