{"record":{"id":"a34112d7e1b98b72","repo":"skylot/jadx","slug":"failed-to-write-res-map-file","errorCode":null,"errorMessage":"Failed to write res-map file","messagePattern":"Failed to write res-map file","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/utils/android/TextResMapFile.java","lineNumber":59,"sourceCode":"\n\tpublic static Map<Integer, String> read(Path resMapFile) {\n\t\ttry (InputStream in = Files.newInputStream(resMapFile)) {\n\t\t\treturn read(in);\n\t\t} catch (Exception e) {\n\t\t\tthrow new JadxRuntimeException(\"Failed to read res-map file\", e);\n\t\t}\n\t}\n\n\tpublic static void write(Path resMapFile, Map<Integer, String> inputResMap) {\n\t\ttry {\n\t\t\tMap<Integer, String> resMap = new TreeMap<>(inputResMap);\n\t\t\tList<String> lines = new ArrayList<>(resMap.size());\n\t\t\tfor (Map.Entry<Integer, String> entry : resMap.entrySet()) {\n\t\t\t\tlines.add(String.format(\"%08x=%s\", entry.getKey(), entry.getValue()));\n\t\t\t}\n\t\t\tFiles.write(resMapFile, lines, StandardCharsets.UTF_8);\n\t\t} catch (Exception e) {\n\t\t\tthrow new JadxRuntimeException(\"Failed to write res-map file\", e);\n\t\t}\n\t}\n}\n","sourceCodeStart":41,"sourceCodeEnd":63,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/utils/android/TextResMapFile.java#L41-L63","documentation":"Thrown when TextResMapFile.write fails to serialize the resource map to disk. The method builds a sorted TreeMap, formats each entry as '%08x=%s', and calls Files.write. Failures include: the target path's parent directory does not exist (NoSuchFileException), the filesystem is read-only or permissions are insufficient (AccessDeniedException), the disk is full (IOException), or the path points to an existing directory.","triggerScenarios":"Calling TextResMapFile.write(Path, Map) where the parent directory of resMapFile has not been created yet. Calling it on a read-only filesystem or a path the JVM process lacks write permission for. Passing a Path that resolves to an already-existing directory. Running out of disk space during Files.write.","commonSituations":"Output directory not pre-created when saving a res-map to a deep nested path. Running jadx in a container with a read-only volume mount. Disk quota exceeded in CI environments. The output path was configured to a system directory like /opt or /etc that requires elevated permissions.","solutions":["Create the parent directory before writing: Files.createDirectories(resMapFile.getParent()).","Verify the parent directory is writable: Files.isWritable(resMapFile.getParent()).","Check available disk space if running in constrained environments.","Ensure the path does not collide with an existing directory name."],"exampleFix":"// before\nTextResMapFile.write(resMapPath, resMap);\n\n// after\nPath parent = resMapPath.getParent();\nif (parent != null) Files.createDirectories(parent);\nTextResMapFile.write(resMapPath, resMap);","handlingStrategy":"validation","validationCode":"public static void ensureWritableTarget(Path file) throws IOException {\n    Path parent = file.getParent();\n    if (parent == null) parent = Path.of(\".\");\n    Files.createDirectories(parent);\n    if (!Files.isWritable(parent)) {\n        throw new AccessDeniedException(\"cannot write to: \" + parent);\n    }\n    if (Files.isDirectory(file)) {\n        throw new IOException(\"target is a directory: \" + file);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    TextResMapFile.write(resMapPath, resMap);\n} catch (JadxRuntimeException e) {\n    Throwable cause = e.getCause();\n    if (cause instanceof NoSuchFileException) {\n        // parent dir missing — create and retry\n        Files.createDirectories(resMapPath.getParent());\n        TextResMapFile.write(resMapPath, resMap);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always create the parent directory with Files.createDirectories before writing.","Verify writable parent before attempting write.","Check available disk space in constrained environments."],"tags":["file-io","res-map","permissions","disk-space","jadx"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}