{"record":{"id":"c44e433b523c68a1","repo":"pxb1988/dex2jar","slug":"error-on-reading-annotation-of-class","errorCode":null,"errorMessage":"error on reading Annotation of class ","messagePattern":"error on reading Annotation of class ","errorType":"exception","errorClass":"DexException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java","lineNumber":813,"sourceCode":"                    int field_annotations_offset = annotationsDirectoryItemIn.getInt();\r\n                    fieldAnnotationPositions.put(field_idx, field_annotations_offset);\r\n                }\r\n                for (int i = 0; i < method_annotation_size; i++) {\r\n                    int method_idx = annotationsDirectoryItemIn.getInt();\r\n                    int method_annotation_offset = annotationsDirectoryItemIn.getInt();\r\n                    methodAnnotationPositions.put(method_idx, method_annotation_offset);\r\n                }\r\n                for (int i = 0; i < parameter_annotation_size; i++) {\r\n                    int method_idx = annotationsDirectoryItemIn.getInt();\r\n                    int parameter_annotation_offset = annotationsDirectoryItemIn.getInt();\r\n                    paramAnnotationPositions.put(method_idx, parameter_annotation_offset);\r\n                }\r\n\r\n                if (class_annotations_off != 0) {\r\n                    try {\r\n                        read_annotation_set_item(class_annotations_off, dcv);\r\n                    } catch (Exception e) {\r\n                        throw new DexException(\"error on reading Annotation of class \", e);\r\n                    }\r\n                }\r\n            }\r\n        } else {\r\n            fieldAnnotationPositions = null;\r\n            methodAnnotationPositions = null;\r\n            paramAnnotationPositions = null;\r\n        }\r\n\r\n        if (class_data_off != 0) {\r\n            ByteBuffer in = classDataIn;\r\n            in.position(class_data_off);\r\n\r\n            int static_fields = readULeb128i(in);\r\n            int instance_fields = readULeb128i(in);\r\n            int direct_methods = readULeb128i(in);\r\n            int virtual_methods = readULeb128i(in);\r\n            {\r","sourceCodeStart":795,"sourceCodeEnd":831,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java#L795-L831","documentation":"DexFileReader wraps any exception from read_annotation_set_item while reading a class's annotations in a DexException('error on reading Annotation of class ', e), preserving the cause. It means the class_annotation_set_off pointed at data that failed to decode (bad offsets, malformed annotation items, or internal reader errors). The original stack trace is in the cause chain.","triggerScenarios":"Opening a dex whose class_def has a nonzero annotations_off pointing to malformed/corrupt annotation_set_item data; offset tables misparsed earlier in the same read; reading dex produced by a broken tool.","commonSituations":"Obfuscated/packed APKs with deliberately mangled annotation offsets; corrupted dex from incomplete zip extraction; dex2jar failing on an app and reporting this wrapper instead of the root cause.","solutions":["Inspect the wrapped cause (e.getCause()) to find the real decode failure and fix that","Re-obtain/re-extract the dex — corruption from bad archive extraction is common","Rebuild the dex from source if you control it; or skip annotations via config flag SKIP_ANNOTATION when constructing DexFileReader","Verify the APK is not packed/protected (packers often corrupt annotation offsets) — unpack first or use a different sample"],"exampleFix":"// before\nDexFileReader r = new DexFileReader(file, 0); // all features\n// after: skip annotations to avoid the fragile path\nint config = DexFileReader.SKIP_CODE | DexFileReader.SKIP_ANNOTATION;\nDexFileReader r = new DexFileReader(file, config);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    new DexFileReader(file, config).accept(visitor);\n} catch (DexException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"error on reading Annotation of class\")) {\n        Throwable root = e; while (root.getCause() != null) root = root.getCause();\n        log.warn(\"Annotations unreadable for \" + file + \": \" + root);\n        return parseSkippingAnnotations(file); // retry with SKIP_ANNOTATION\n    }\n    throw e;\n}","preventionTips":["Always log/getCause() — this is a wrapper; the real bug is the cause","Retry parsing with DexFileReader.SKIP_ANNOTATION when annotation data is not needed","Verify APK integrity (zip test) before analysis; packed apps often have mangled offsets"],"tags":["dex","annotation","wrapped-exception"],"backgroundTag":"file-read-failed","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}