{"record":{"id":"39dfeb7320fca59c","repo":"skylot/jadx","slug":"failed-to-init-common-directories","errorCode":null,"errorMessage":"Failed to init common directories","messagePattern":"Failed to init common directories","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"jadx-commons/jadx-app-commons/src/main/java/jadx/commons/app/JadxCommonFiles.java","lineNumber":48,"sourceCode":"\t}\n\n\tstatic {\n\t\tDirsLoader loader = new DirsLoader();\n\t\tCONFIG_DIR = loader.getConfigDir();\n\t\tCACHE_DIR = loader.getCacheDir();\n\t}\n\n\tprivate static final class DirsLoader {\n\t\tprivate final Path configDir;\n\t\tprivate final Path cacheDir;\n\n\t\tDirsLoader() {\n\t\t\ttry {\n\t\t\t\tAtomicReference<@Nullable ProjectDirectories> pdRef = new AtomicReference<>();\n\t\t\t\tconfigDir = loadEnvDir(\"JADX_CONFIG_DIR\", () -> loadDirs(pdRef).configDir);\n\t\t\t\tcacheDir = loadEnvDir(\"JADX_CACHE_DIR\", () -> loadDirs(pdRef).cacheDir);\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException(\"Failed to init common directories\", e);\n\t\t\t}\n\t\t}\n\n\t\tprivate static Path loadEnvDir(String envVar, Supplier<String> dirFunc) throws IOException {\n\t\t\tString envDir = JadxCommonEnv.get(envVar, null);\n\t\t\tString dirStr;\n\t\t\tif (envDir != null) {\n\t\t\t\tdirStr = envDir;\n\t\t\t} else {\n\t\t\t\tdirStr = dirFunc.get();\n\t\t\t}\n\t\t\tPath path = Path.of(dirStr).toAbsolutePath();\n\t\t\tFiles.createDirectories(path);\n\t\t\treturn path;\n\t\t}\n\n\t\tprivate static ProjectDirectories loadDirs(AtomicReference<@Nullable ProjectDirectories> pdRef) {\n\t\t\tProjectDirectories currentDirs = pdRef.get();","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-commons/jadx-app-commons/src/main/java/jadx/commons/app/JadxCommonFiles.java#L30-L66","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Unset JADX_CONFIG_DIR and JADX_CACHE_DIR to use OS defaults.","Set them to absolute, writable paths.","Check the wrapped cause for the specific IO or parse error.","Ensure the user/home directory is accessible (HOME set correctly on Linux/macOS)."],"exampleFix":"// before\nJADX_CONFIG_DIR= ./jadx jadx ...\n// after\nJADX_CONFIG_DIR=$HOME/.config/jadx jadx ...","handlingStrategy":"try-catch","validationCode":"// Check env vars before any jadx API call\nString cfg = System.getenv(\"JADX_CONFIG_DIR\");\nString cache = System.getenv(\"JADX_CACHE_DIR\");\nif (cfg != null && !Files.isWritable(Paths.get(cfg).getParent() == null ? Paths.get(\".\") : Paths.get(cfg).getParent())) {\n    throw new IllegalStateException(\"JADX_CONFIG_DIR not writable: \" + cfg);\n}\nif (cache != null && !Files.isWritable(Paths.get(cache))) {\n    throw new IllegalStateException(\"JADX_CACHE_DIR not writable: \" + cache);\n}","typeGuard":"public static boolean envDirsOk() {\n    for (String v : List.of(\"JADX_CONFIG_DIR\", \"JADX_CACHE_DIR\")) {\n        String p = System.getenv(v);\n        if (p == null || p.isEmpty()) continue;\n        try { Files.createDirectories(Paths.get(p)); } catch (IOException e) { return false; }\n    }\n    return true;\n}","tryCatchPattern":"// This fires during static init — catch at application entry\ntry {\n    Class.forName(\"jadx.commons.app.JadxCommonFiles\");\n} catch (ExceptionInInitializerError e) {\n    Throwable c = e.getCause();\n    if (c instanceof RuntimeException && c.getMessage().equals(\"Failed to init common directories\")) {\n        System.err.println(\"Fix JADX_CONFIG_DIR/JADX_CACHE_DIR env vars: \" + c.getCause());\n        System.exit(1);\n    }\n    throw e;\n}","preventionTips":["Point JADX_CONFIG_DIR/JADX_CACHE_DIR at absolute, writable paths.","Ensure HOME is set and accessible on POSIX systems.","Do not set these env vars to empty strings."],"tags":["config","init","environment","io","jadx"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}