{"record":{"id":"d6f7994b75d0e472","repo":"skylot/jadx","slug":"failed-to-write-metadata-file","errorCode":null,"errorMessage":"Failed to write metadata file","messagePattern":"Failed to write metadata file","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-gui/src/main/java/jadx/gui/cache/code/disk/CodeMetadataAdapter.java","lineNumber":50,"sourceCode":"\npublic class CodeMetadataAdapter {\n\tprivate static final byte[] JADX_METADATA_HEADER = \"jadxmd\".getBytes(StandardCharsets.US_ASCII);\n\n\tprivate final CodeAnnotationAdapter codeAnnotationAdapter;\n\n\tpublic CodeMetadataAdapter(RootNode root) {\n\t\tcodeAnnotationAdapter = new CodeAnnotationAdapter(root);\n\t}\n\n\tpublic void write(Path metadataFile, ICodeMetadata metadata) {\n\t\tFileUtils.makeDirsForFile(metadataFile);\n\t\ttry (OutputStream fileOutput = Files.newOutputStream(metadataFile, WRITE, CREATE, TRUNCATE_EXISTING);\n\t\t\t\tDataOutputStream out = new DataOutputStream(new BufferedOutputStream(fileOutput))) {\n\t\t\tout.write(JADX_METADATA_HEADER);\n\t\t\twriteLines(out, metadata.getLineMapping());\n\t\t\twriteAnnotations(out, metadata.getAsMap());\n\t\t} catch (Exception e) {\n\t\t\tthrow new RuntimeException(\"Failed to write metadata file\", e);\n\t\t}\n\t}\n\n\tpublic ICodeInfo readAndBuild(Path metadataFile, String code) {\n\t\tif (!Files.exists(metadataFile)) {\n\t\t\treturn new SimpleCodeInfo(code);\n\t\t}\n\t\ttry (InputStream fileInput = Files.newInputStream(metadataFile);\n\t\t\t\tDataInputStream in = new DataInputStream(new BufferedInputStream(fileInput))) {\n\t\t\tin.skipBytes(JADX_METADATA_HEADER.length);\n\t\t\tMap<Integer, Integer> lines = readLines(in);\n\t\t\tMap<Integer, ICodeAnnotation> annotations = readAnnotations(in);\n\t\t\treturn new AnnotatedCodeInfo(code, lines, annotations);\n\t\t} catch (Exception e) {\n\t\t\tthrow new RuntimeException(\"Failed to parse code annotations\", e);\n\t\t}\n\t}\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-gui/src/main/java/jadx/gui/cache/code/disk/CodeMetadataAdapter.java#L32-L68","documentation":"CodeMetadataAdapter.write serializes code metadata (line mappings and annotations) to a .jadxmd file using a DataOutputStream. If any IO or serialization error occurs during writing, it is wrapped in a RuntimeException. This is part of jadx-gui's disk code cache for faster subsequent decompilation.","triggerScenarios":"write() opens the metadata file with CREATE+TRUNCATE_EXISTING, writes a header and line/annotation maps. Any exception (disk full, permission error, serialization failure) triggers the RuntimeException. Called by DiskCodeCache's async write pool during background caching.","commonSituations":"Disk full or quota exceeded in the cache directory. Permission issues in the user's cache directory. Concurrent file access or locking. Corrupted cache state from a previous interrupted write. JVM running out of memory during large annotation serialization.","solutions":["Free disk space in the cache directory (typically under the user home or temp)","Check permissions on the jadx cache directory","Clear the jadx cache directory to reset state","Reduce the number of classes or disable code caching in jadx settings"],"exampleFix":"// Clear the cache directory manually:\n// Linux/Mac: rm -rf ~/.jadx/cache\n// Or in jadx-gui: File > Clear Cache\n// No API code fix needed — this is an internal cache write.","handlingStrategy":"try-catch","validationCode":"// Ensure cache directory is writable and has space before starting\nPath cacheDir = JadxFiles.CACHE_DIR;\nFiles.createDirectories(cacheDir);\nif (!Files.isWritable(cacheDir)) { throw new IllegalStateException(\"Cache dir not writable\"); }","typeGuard":null,"tryCatchPattern":"// Internal to jadx-gui; no caller API. Clear cache on failure:\n// catch is inside DiskCodeCache; user action is to clear the cache dir.","preventionTips":["Keep the cache directory on a local disk with free space","Clear the cache periodically or after jadx upgrades","Avoid running multiple jadx instances sharing one cache"],"tags":["cache","io","filesystem","serialization","jadx-gui"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}