skylot/jadx · critical · RuntimeException

Failed to init common directories

Error message

Failed to init common directories

What it means

Thrown by JadxCommonFiles.DirsLoader constructor as a RuntimeException wrapping any exception during config/cache directory resolution. The loader reads JADX_CONFIG_DIR / JADX_CACHE_DIR env vars or falls back to OS ProjectDirectories lookup; any failure (env parse, IO, directories-lib error) is bundled into this message.

Source

Thrown at jadx-commons/jadx-app-commons/src/main/java/jadx/commons/app/JadxCommonFiles.java:48

	}

	static {
		DirsLoader loader = new DirsLoader();
		CONFIG_DIR = loader.getConfigDir();
		CACHE_DIR = loader.getCacheDir();
	}

	private static final class DirsLoader {
		private final Path configDir;
		private final Path cacheDir;

		DirsLoader() {
			try {
				AtomicReference<@Nullable ProjectDirectories> pdRef = new AtomicReference<>();
				configDir = loadEnvDir("JADX_CONFIG_DIR", () -> loadDirs(pdRef).configDir);
				cacheDir = loadEnvDir("JADX_CACHE_DIR", () -> loadDirs(pdRef).cacheDir);
			} catch (Exception e) {
				throw new RuntimeException("Failed to init common directories", e);
			}
		}

		private static Path loadEnvDir(String envVar, Supplier<String> dirFunc) throws IOException {
			String envDir = JadxCommonEnv.get(envVar, null);
			String dirStr;
			if (envDir != null) {
				dirStr = envDir;
			} else {
				dirStr = dirFunc.get();
			}
			Path path = Path.of(dirStr).toAbsolutePath();
			Files.createDirectories(path);
			return path;
		}

		private static ProjectDirectories loadDirs(AtomicReference<@Nullable ProjectDirectories> pdRef) {
			ProjectDirectories currentDirs = pdRef.get();

View on GitHub (pinned to e738a26571)

Solutions

  1. Unset JADX_CONFIG_DIR and JADX_CACHE_DIR to use OS defaults.
  2. Set them to absolute, writable paths.
  3. Check the wrapped cause for the specific IO or parse error.
  4. Ensure the user/home directory is accessible (HOME set correctly on Linux/macOS).

Example fix

// before
JADX_CONFIG_DIR= ./jadx jadx ...
// after
JADX_CONFIG_DIR=$HOME/.config/jadx jadx ...
Defensive patterns

Strategy: try-catch

Validate before calling

// Check env vars before any jadx API call
String cfg = System.getenv("JADX_CONFIG_DIR");
String cache = System.getenv("JADX_CACHE_DIR");
if (cfg != null && !Files.isWritable(Paths.get(cfg).getParent() == null ? Paths.get(".") : Paths.get(cfg).getParent())) {
    throw new IllegalStateException("JADX_CONFIG_DIR not writable: " + cfg);
}
if (cache != null && !Files.isWritable(Paths.get(cache))) {
    throw new IllegalStateException("JADX_CACHE_DIR not writable: " + cache);
}

Type guard

public static boolean envDirsOk() {
    for (String v : List.of("JADX_CONFIG_DIR", "JADX_CACHE_DIR")) {
        String p = System.getenv(v);
        if (p == null || p.isEmpty()) continue;
        try { Files.createDirectories(Paths.get(p)); } catch (IOException e) { return false; }
    }
    return true;
}

Try / catch

// This fires during static init — catch at application entry
try {
    Class.forName("jadx.commons.app.JadxCommonFiles");
} catch (ExceptionInInitializerError e) {
    Throwable c = e.getCause();
    if (c instanceof RuntimeException && c.getMessage().equals("Failed to init common directories")) {
        System.err.println("Fix JADX_CONFIG_DIR/JADX_CACHE_DIR env vars: " + c.getCause());
        System.exit(1);
    }
    throw e;
}

Prevention

When it happens

Trigger: Setting JADX_CONFIG_DIR or JADX_CACHE_DIR to an invalid/unusable path, or the underlying directories library failing to resolve OS-specific directories. Because this runs during static init of JadxCommonFiles, the error surfaces very early at first use of any jadx API.

Common situations: JADX_CONFIG_DIR/JADX_CACHE_DIR pointing to a path that cannot be created or is not absolute; running on an OS/locale where directories-lib cannot determine config home; permission denied creating the directory; env var set to an empty or malformed value.

Related errors


AI-assisted analysis of skylot/jadx@e738a26571 (2026-08-14). Data as JSON: /api/errors/39dfeb7320fca59c. Report an issue: GitHub.