{"record":{"id":"9275d4390f2a19de","repo":"skylot/jadx","slug":"failed-to-parse-code-annotations","errorCode":null,"errorMessage":"Failed to parse code annotations","messagePattern":"Failed to parse code annotations","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-gui/src/main/java/jadx/gui/cache/code/disk/CodeMetadataAdapter.java","lineNumber":65,"sourceCode":"\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\n\tprivate void writeLines(DataOutput out, Map<Integer, Integer> lines) throws IOException {\n\t\tout.writeInt(lines.size());\n\t\tfor (Map.Entry<Integer, Integer> entry : lines.entrySet()) {\n\t\t\tDataAdapterHelper.writeUVInt(out, entry.getKey());\n\t\t\tDataAdapterHelper.writeUVInt(out, entry.getValue());\n\t\t}\n\t}\n\n\tprivate Map<Integer, Integer> readLines(DataInput in) throws IOException {\n\t\tint size = in.readInt();\n\t\tif (size == 0) {\n\t\t\treturn Collections.emptyMap();\n\t\t}\n\t\tMap<Integer, Integer> lines = new HashMap<>(size);\n\t\tfor (int i = 0; i < size; i++) {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-gui/src/main/java/jadx/gui/cache/code/disk/CodeMetadataAdapter.java#L47-L83","documentation":"CodeMetadataAdapter.readAndBuild reads a cached .jadxmd file to reconstruct code annotations. If the file is corrupted, truncated, or written by an incompatible jadx version, deserialization fails and a RuntimeException is thrown. This only triggers when a pre-existing cache file exists.","triggerScenarios":"readAndBuild opens the metadata file, skips the header, reads line mappings and annotations via DataInputStream. Any exception (EOFException, malformed UVInt, negative array size, version mismatch) is caught and wrapped. Called when loading a previously cached class from disk.","commonSituations":"Cache written by an older or newer jadx version with a different format. Cache file truncated by a crash or disk-full during a previous write. Cache directory modified or partially deleted by external processes. OS or antivirus corrupting cache files.","solutions":["Clear the jadx cache directory to force a fresh decompilation","Upgrade jadx — cache format version checks may have been added","Ensure the cache directory is not shared across jadx versions","Disable disk caching if the problem recurs"],"exampleFix":"// Clear cache to resolve format corruption:\n// rm -rf ~/.cache/jadx  (or the configured cache dir)\n// Or set a fresh cache location in jadx-gui settings.","handlingStrategy":"fallback","validationCode":"// Clear cache before loading if version changed\nPath metaFile = cacheDir.resolve(clsId + \".jadxmd\");\nif (isIncompatibleVersion(metaFile)) { Files.deleteIfExists(metaFile); }","typeGuard":null,"tryCatchPattern":"// This is internal; the catch in readAndBuild rethrows. User remedy:\n// delete the cache directory to force fresh decompilation.","preventionTips":["Clear cache after upgrading jadx","Do not share cache across jadx versions","Keep cache on stable local storage"],"tags":["cache","io","serialization","corrupt-cache","jadx-gui"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}