Skip to content

Commit

Permalink
fix(gui): add volatile and update sync for decompiler field in wrapper (
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Jun 8, 2022
1 parent 20657e8 commit 14fd88b
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions jadx-gui/src/main/java/jadx/gui/JadxWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@
import static jadx.core.dex.nodes.ProcessState.NOT_LOADED;
import static jadx.core.dex.nodes.ProcessState.PROCESS_COMPLETE;

@SuppressWarnings("ConstantConditions")
public class JadxWrapper {
private static final Logger LOG = LoggerFactory.getLogger(JadxWrapper.class);

private static final Object DECOMPILER_UPDATE_SYNC = new Object();

private final MainWindow mainWindow;
private @Nullable JadxDecompiler decompiler;
private volatile @Nullable JadxDecompiler decompiler;

public JadxWrapper(MainWindow mainWindow) {
this.mainWindow = mainWindow;
Expand All @@ -52,14 +55,16 @@ public JadxWrapper(MainWindow mainWindow) {
public void open() {
close();
try {
JadxProject project = getProject();
JadxArgs jadxArgs = getSettings().toJadxArgs();
jadxArgs.setInputFiles(FileUtils.toFiles(project.getFilePaths()));
jadxArgs.setCodeData(project.getCodeData());

this.decompiler = new JadxDecompiler(jadxArgs);
this.decompiler.load();
initCodeCache();
synchronized (DECOMPILER_UPDATE_SYNC) {
JadxProject project = getProject();
JadxArgs jadxArgs = getSettings().toJadxArgs();
jadxArgs.setInputFiles(FileUtils.toFiles(project.getFilePaths()));
jadxArgs.setCodeData(project.getCodeData());

this.decompiler = new JadxDecompiler(jadxArgs);
this.decompiler.load();
initCodeCache();
}
} catch (Exception e) {
LOG.error("Jadx decompiler wrapper init error", e);
close();
Expand All @@ -77,13 +82,15 @@ public void unloadClasses() {

public void close() {
try {
if (decompiler != null) {
decompiler.close();
synchronized (DECOMPILER_UPDATE_SYNC) {
if (decompiler != null) {
decompiler.close();
decompiler = null;
}
}
} catch (Exception e) {
LOG.error("Jadx decompiler close error", e);
} finally {
decompiler = null;
mainWindow.getCacheObject().reset();
}
}
Expand Down

0 comments on commit 14fd88b

Please sign in to comment.