未验证 提交 14fd88b2 编写于 作者: S Skylot

fix(gui): add volatile and update sync for decompiler field in wrapper (#1518)

上级 20657e8b
...@@ -39,11 +39,14 @@ import static jadx.core.dex.nodes.ProcessState.GENERATED_AND_UNLOADED; ...@@ -39,11 +39,14 @@ import static jadx.core.dex.nodes.ProcessState.GENERATED_AND_UNLOADED;
import static jadx.core.dex.nodes.ProcessState.NOT_LOADED; import static jadx.core.dex.nodes.ProcessState.NOT_LOADED;
import static jadx.core.dex.nodes.ProcessState.PROCESS_COMPLETE; import static jadx.core.dex.nodes.ProcessState.PROCESS_COMPLETE;
@SuppressWarnings("ConstantConditions")
public class JadxWrapper { public class JadxWrapper {
private static final Logger LOG = LoggerFactory.getLogger(JadxWrapper.class); private static final Logger LOG = LoggerFactory.getLogger(JadxWrapper.class);
private static final Object DECOMPILER_UPDATE_SYNC = new Object();
private final MainWindow mainWindow; private final MainWindow mainWindow;
private @Nullable JadxDecompiler decompiler; private volatile @Nullable JadxDecompiler decompiler;
public JadxWrapper(MainWindow mainWindow) { public JadxWrapper(MainWindow mainWindow) {
this.mainWindow = mainWindow; this.mainWindow = mainWindow;
...@@ -52,14 +55,16 @@ public class JadxWrapper { ...@@ -52,14 +55,16 @@ public class JadxWrapper {
public void open() { public void open() {
close(); close();
try { try {
JadxProject project = getProject(); synchronized (DECOMPILER_UPDATE_SYNC) {
JadxArgs jadxArgs = getSettings().toJadxArgs(); JadxProject project = getProject();
jadxArgs.setInputFiles(FileUtils.toFiles(project.getFilePaths())); JadxArgs jadxArgs = getSettings().toJadxArgs();
jadxArgs.setCodeData(project.getCodeData()); jadxArgs.setInputFiles(FileUtils.toFiles(project.getFilePaths()));
jadxArgs.setCodeData(project.getCodeData());
this.decompiler = new JadxDecompiler(jadxArgs);
this.decompiler.load(); this.decompiler = new JadxDecompiler(jadxArgs);
initCodeCache(); this.decompiler.load();
initCodeCache();
}
} catch (Exception e) { } catch (Exception e) {
LOG.error("Jadx decompiler wrapper init error", e); LOG.error("Jadx decompiler wrapper init error", e);
close(); close();
...@@ -77,13 +82,15 @@ public class JadxWrapper { ...@@ -77,13 +82,15 @@ public class JadxWrapper {
public void close() { public void close() {
try { try {
if (decompiler != null) { synchronized (DECOMPILER_UPDATE_SYNC) {
decompiler.close(); if (decompiler != null) {
decompiler.close();
decompiler = null;
}
} }
} catch (Exception e) { } catch (Exception e) {
LOG.error("Jadx decompiler close error", e); LOG.error("Jadx decompiler close error", e);
} finally { } finally {
decompiler = null;
mainWindow.getCacheObject().reset(); mainWindow.getCacheObject().reset();
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册