{"record":{"id":"8770b77bd763f94e","repo":"skylot/jadx","slug":"failed-to-build-local-cache-dir","errorCode":null,"errorMessage":"Failed to build local cache dir","messagePattern":"Failed to build local cache dir","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-gui/src/main/java/jadx/gui/cache/manager/CacheManager.java","lineNumber":125,"sourceCode":"\t}\n\n\tprivate Path buildCacheDir(JadxProject project) {\n\t\tString cacheDirValue = settings.getCacheDir();\n\t\tif (Objects.equals(cacheDirValue, \".\")) {\n\t\t\treturn buildLocalCacheDir(project);\n\t\t}\n\t\tPath cacheBaseDir = cacheDirValue == null ? JadxFiles.PROJECTS_CACHE_DIR : Paths.get(cacheDirValue);\n\t\treturn cacheBaseDir.resolve(buildProjectUniqName(project));\n\t}\n\n\tprivate static Path buildLocalCacheDir(JadxProject project) {\n\t\tPath projectPath = project.getProjectPath();\n\t\tif (projectPath != null) {\n\t\t\treturn projectPath.resolveSibling(projectPath.getFileName() + \".cache\");\n\t\t}\n\t\tList<Path> files = project.getFilePaths();\n\t\tif (files.isEmpty()) {\n\t\t\tthrow new JadxRuntimeException(\"Failed to build local cache dir\");\n\t\t}\n\t\tPath path = files.stream()\n\t\t\t\t.filter(p -> !p.getFileName().toString().endsWith(\".jadx.kts\"))\n\t\t\t\t.findFirst()\n\t\t\t\t.orElseGet(() -> files.get(0));\n\t\tString name = CommonFileUtils.removeFileExtension(path.getFileName().toString());\n\t\treturn path.resolveSibling(name + \".jadx.cache\");\n\t}\n\n\tprivate Path verifyEntry(JadxProject project, Path cacheDir) {\n\t\tboolean cacheExists = Files.exists(cacheDir);\n\t\tString key = projectToKey(project);\n\t\tCacheEntry entry = cacheMap.get(key);\n\t\tif (entry == null) {\n\t\t\tPath newCacheDir = cacheExists ? cacheDir : buildCacheDir(project);\n\t\t\taddEntry(key, newCacheDir);\n\t\t\treturn newCacheDir;\n\t\t}","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-gui/src/main/java/jadx/gui/cache/manager/CacheManager.java#L107-L143","documentation":"CacheManager.buildLocalCacheDir constructs a local cache path next to the project or input files. If the project has no project path AND no file paths (files.isEmpty()), there is no basis for deriving a sibling cache directory, so a JadxRuntimeException is thrown.","triggerScenarios":"buildLocalCacheDir checks projectPath first (uses it if present), then falls back to project.getFilePaths(). If the file list is empty — meaning the project was created with no inputs and no saved path — the method cannot determine where to place the cache and throws.","commonSituations":"Programmatically creating a JadxProject without adding any input files or saving a project path. A corrupted or newly-initialized project state where file paths were cleared. Calling cache operations before loading any inputs.","solutions":["Ensure at least one input file is added to the project before invoking cache operations","Set a project path via project.save() before cache initialization","Add input files via project.addFile(path) or equivalent API before triggering cache build","Initialize the project from a valid saved state rather than an empty object"],"exampleFix":"// Before any cache operation, ensure the project has inputs:\nJadxProject project = new JadxProject();\nproject.addFile(Path.of(\"app.apk\")); // ensure non-empty file list\nproject.setProjectPath(Path.of(\"app.jadx.kts\")); // or set a project path\n// Now cache operations will succeed.","handlingStrategy":"validation","validationCode":"// Ensure project has inputs before cache operations\nif (project.getFilePaths().isEmpty() && project.getProjectPath() == null) {\n    throw new IllegalStateException(\"Add input files before cache operations\");\n}","typeGuard":"boolean hasInputs = !project.getFilePaths().isEmpty() || project.getProjectPath() != null;\nif (hasInputs) { /* safe to build cache dir */ }","tryCatchPattern":"try {\n    cacheManager.getLocalCacheDir(project);\n} catch (JadxRuntimeException e) {\n    if (e.getMessage().contains(\"Failed to build local cache dir\")) {\n        LOG.error(\"Project has no input files — cannot build cache\", e);\n        // add inputs and retry\n    }\n}","preventionTips":["Always add at least one input file before any cache operation","Save the project to establish a projectPath","Validate project state before initialization"],"tags":["cache","project-state","configuration","jadx-gui"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}