pxb1988/dex2jar · error · DexException
error on reading Annotation of class
Error message
error on reading Annotation of class
What it means
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.
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
Example fix
// before DexFileReader r = new DexFileReader(file, 0); // all features // after: skip annotations to avoid the fragile path int config = DexFileReader.SKIP_CODE | DexFileReader.SKIP_ANNOTATION; DexFileReader r = new DexFileReader(file, config);
Defensive patterns
Strategy: try-catch
Try / catch
try {
new DexFileReader(file, config).accept(visitor);
} catch (DexException e) {
if (e.getMessage() != null && e.getMessage().startsWith("error on reading Annotation of class")) {
Throwable root = e; while (root.getCause() != null) root = root.getCause();
log.warn("Annotations unreadable for " + file + ": " + root);
return parseSkippingAnnotations(file); // retry with SKIP_ANNOTATION
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- while accept annotation in field
- while accept annotation in method
- Odex unsupported.
- Magic unsupported.
- Endian_tag unsupported
AI-assisted analysis of pxb1988/dex2jar@b5bda4fb49 (2026-09-08).
Data as JSON: /api/errors/c44e433b523c68a1.
Report an issue: GitHub.
Appendix: source
Thrown at dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java:813
int field_annotations_offset = annotationsDirectoryItemIn.getInt();
fieldAnnotationPositions.put(field_idx, field_annotations_offset);
}
for (int i = 0; i < method_annotation_size; i++) {
int method_idx = annotationsDirectoryItemIn.getInt();
int method_annotation_offset = annotationsDirectoryItemIn.getInt();
methodAnnotationPositions.put(method_idx, method_annotation_offset);
}
for (int i = 0; i < parameter_annotation_size; i++) {
int method_idx = annotationsDirectoryItemIn.getInt();
int parameter_annotation_offset = annotationsDirectoryItemIn.getInt();
paramAnnotationPositions.put(method_idx, parameter_annotation_offset);
}
if (class_annotations_off != 0) {
try {
read_annotation_set_item(class_annotations_off, dcv);
} catch (Exception e) {
throw new DexException("error on reading Annotation of class ", e);
}
}
}
} else {
fieldAnnotationPositions = null;
methodAnnotationPositions = null;
paramAnnotationPositions = null;
}
if (class_data_off != 0) {
ByteBuffer in = classDataIn;
in.position(class_data_off);
int static_fields = readULeb128i(in);
int instance_fields = readULeb128i(in);
int direct_methods = readULeb128i(in);
int virtual_methods = readULeb128i(in);
{
View on GitHub (pinned to b5bda4fb49)