pxb1988/dex2jar · error · DexException

while accept annotation in method

Error message

while accept annotation in method:%s.

What it means

While visiting a method, DexFileReader wraps exceptions from read_annotation_set_item (and, in the same block, read_annotation_set_ref_list for parameter annotations) in DexException('while accept annotation in method:%s.', method). It means a method's (or its parameters') annotation data at the recorded offset failed to decode, with the root cause preserved.

Solutions

  1. Check getCause() for the underlying decode error and address that
  2. Rebuild the dex from source with current tooling to regenerate annotation sections
  3. Use the SKIP_ANNOTATION config flag when creating DexFileReader to skip method/parameter annotations
  4. Unpack/deprotect the APK if a packer is known to have altered it

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 method:")) {
        String method = e.getMessage().substring("while accept annotation in method:".length());
        log.warn("Skipping annotations of method " + method, e.getCause());
        return parseSkippingAnnotations(file); // retry with SKIP_ANNOTATION
    }
    throw e;
}

Prevention

When it happens

Trigger: method_annotation or parameter_annotation offsets pointing to corrupt/malformed annotation_set_item or annotation_set_ref_list data; obfuscated/packed dex with mangled offsets; damaged sections after bad repackaging.

Common situations: Analyzing hardened Android apps (packers corrupting annotation tables); dex2jar conversion failing on store-bought APKs; dex produced by non-standard compilers with bad parameter annotation lists.

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/fa730d1d3a496ec2. Report an issue: GitHub.

Appendix: source

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

            }
        }

        // issue 195, a <clinit> or <init> but not marked as ACC_CONSTRUCTOR,
        if (0 == (method_access_flags & DexConstants.ACC_CONSTRUCTOR)
                && (method.getName().equals("<init>") || method.getName().equals("<clinit>"))) {
            WARN("GLITCH: method %s @%08x not marked as ACC_CONSTRUCTOR", method.toString(), offset);
        }

        try {
            DexMethodVisitor dmv = cv.visitMethod(method_access_flags, method);
            if (dmv != null) {
                if ((config & SKIP_ANNOTATION) == 0) {
                    Integer annotation_offset = methodAnnos.get(method_id);
                    if (annotation_offset != null) {
                        try {
                            read_annotation_set_item(annotation_offset, dmv);
                        } catch (Exception e) {
                            throw new DexException(e, "while accept annotation in method:%s.", method.toString());
                        }
                    }
                    Integer parameter_annotation_offset = parameterAnnos.get(method_id);
                    if (parameter_annotation_offset != null) {
                        try {
                            read_annotation_set_ref_list(parameter_annotation_offset, dmv);
                        } catch (Exception e) {
                            throw new DexException(e, "while accept parameter annotation in method:%s.",
                                    method.toString());
                        }
                    }
                }
                if (code_off != 0) {
                    boolean keep = true;
                    if (0 != (SKIP_CODE & config)) {
                        keep = 0 != (KEEP_CLINIT & config) && method.getName().equals("<clinit>");
                    }
                    if(keep) {

View on GitHub (pinned to b5bda4fb49)