Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer TEMP_ROOT_DIR creation #2131

Open
NebelNidas opened this issue Mar 23, 2024 · 0 comments
Open

Defer TEMP_ROOT_DIR creation #2131

NebelNidas opened this issue Mar 23, 2024 · 0 comments

Comments

@NebelNidas
Copy link
Contributor

NebelNidas commented Mar 23, 2024

Currently, this folder is created as soon as the FileUtils class gets loaded by the JVM:

private static final Path TEMP_ROOT_DIR = createTempRootDir();
private static Path createTempRootDir() {
try {
String jadxTmpDir = System.getenv("JADX_TMP_DIR");
Path dir;
if (jadxTmpDir != null) {
dir = Files.createTempDirectory(Paths.get(jadxTmpDir), "jadx-instance-");
} else {
dir = Files.createTempDirectory(JADX_TMP_INSTANCE_PREFIX);
}
dir.toFile().deleteOnExit();
return dir;
} catch (Exception e) {
throw new JadxRuntimeException("Failed to create temp root directory", e);
}
}

Usually that's not a problem, but I'm currently encountering an issue on Windows where this behavior leads to a crash:

Caused by: jadx.core.utils.exceptions.JadxRuntimeException: Failed to create temp root directory
        at jadx.core.utils.files.FileUtils.createTempRootDir(FileUtils.java:165)
        at jadx.core.utils.files.FileUtils.<clinit>(FileUtils.java:151)
        ... 31 more
Caused by: java.nio.file.AccessDeniedException: C:\Windows\jadx-instance-3513248238493422666
        at jadx.core.utils.files.FileUtils.createTempRootDir(FileUtils.java:160)
        ... 32 more

Changing the JADX_TMP_DIR environment variable or the java.io.tmpdir system property surprisingly has no effect. I have no idea how that's possible, and didn't find any related info online, so until I find the root cause, it would be nice if you could just defer the folder creation until it's actually required by JADX for now.

If you want to reproduce the issue: Clone this branch and run ./gradlew test --tests '*DecompileTest' (requires JDK >=17). The astonishing thing is that it doesn't seem to fail when run through GitHub Actions, but I have been able to reproduce the crash on at least two physical and one virtual machine of mine (Windows 10 22H2, multiple JDK vendors). Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant