pxb1988/dex2jar · error · DexException

while accept annotation in field

Error message

while accept annotation in field:%s.

What it means

While visiting a field, DexFileReader wraps any exception from read_annotation_set_item in DexException('while accept annotation in field:%s.', field) naming the field via its DexField toString. The annotation_set_item at the recorded offset failed to decode. The root cause is in the exception's cause chain.

Solutions

  1. Unwrap and inspect getCause() to find the actual annotation decode failure
  2. Rebuild the dex from source with d8/dx to regenerate valid annotation offsets
  3. Construct the reader with SKIP_ANNOTATION in the config to bypass annotation decoding entirely
  4. If the app is packed, unpack/deprotect it first before running dex analysis

Example fix

// before
DexFileReader reader = new DexFileReader(file, 0);
// after
DexFileReader reader = new DexFileReader(file, DexFileReader.SKIP_ANNOTATION);
Defensive patterns

Strategy: try-catch

Try / catch

try {
    new DexFileReader(file, config).accept(visitor);
} catch (DexException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("while accept annotation in field:")) {
        String field = e.getMessage().substring("while accept annotation in field:".length());
        log.warn("Skipping annotations of field " + field, e.getCause());
        return parseSkippingAnnotations(file); // retry with SKIP_ANNOTATION
    }
    throw e;
}

Prevention

When it happens

Trigger: A field_annotation entry whose annotations_off points to malformed annotation data (bad encoded_value bytes, offset out of bounds); reading an obfuscated or corrupted dex where field annotation offsets were mangled.

Common situations: Packed/protected APKs from app stores; dex rewritten by repackaging tools that moved sections without fixing offsets; dex2jar pipelines converting such apps.

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


AI-assisted analysis of pxb1988/dex2jar@b5bda4fb49 (2026-09-08). Data as JSON: /api/errors/767d92bcc8ee54c6. Report an issue: GitHub.

Appendix: source

Thrown at dex-reader/src/main/java/com/googlecode/d2j/reader/DexFileReader.java:999

        return getString(typeIdIn.getInt(id * 4));
    }

    private int acceptField(ByteBuffer in, int lastIndex, DexClassVisitor dcv,
            Map<Integer, Integer> fieldAnnotationPositions, Object value, int config) {
        int diff = readULeb128i(in);
        int field_access_flags = readULeb128i(in);
        int field_id = lastIndex + diff;
        Field field = getField(field_id);
        // //////////////////////////////////////////////////////////////
        DexFieldVisitor dfv = dcv.visitField(field_access_flags, field, value);
        if (dfv != null) {
            if ((config & SKIP_ANNOTATION) == 0) {
                Integer annotation_offset = fieldAnnotationPositions.get(field_id);
                if (annotation_offset != null) {
                    try {
                        read_annotation_set_item(annotation_offset, dfv);
                    } catch (Exception e) {
                        throw new DexException(e, "while accept annotation in field:%s.", field.toString());
                    }
                }
            }
            dfv.visitEnd();
        }
        // //////////////////////////////////////////////////////////////
        return field_id;
    }

    private int acceptMethod(ByteBuffer in, int lastIndex, DexClassVisitor cv, Map<Integer, Integer> methodAnnos,
            Map<Integer, Integer> parameterAnnos, int config, boolean firstMethod) {
        int offset = in.position();
        int diff = readULeb128i(in);
        int method_access_flags = readULeb128i(in);
        int code_off = readULeb128i(in);
        int method_id = lastIndex + diff;
        Method method = getMethod(method_id);

View on GitHub (pinned to b5bda4fb49)