skylot/jadx · error · JadxRuntimeException

Method generation error

Error message

Method generation error

What it means

A wrapper thrown by the JSON code generator (JsonCodeGen.fillMthCode) when mthGen.addInstructions(cw) raises any exception while producing the JSON representation of a method's body. The original cause is preserved. It surfaces only when JSON output mode is enabled, not in normal Java-source export.

Source

Thrown at jadx-core/src/main/java/jadx/core/codegen/json/JsonCodeGen.java:175

			mthGen.addDefinition(cw);
			jsonMth.setDeclaration(cw.getCodeStr());
			jsonMth.setAccessFlags(mth.getAccessFlags().rawValue());
			jsonMth.setLines(fillMthCode(mth, mthGen));
			jsonMth.setOffset("0x" + Long.toHexString(mth.getMethodCodeOffset()));
			jsonCls.getMethods().add(jsonMth);
		}
	}

	private List<JsonCodeLine> fillMthCode(MethodNode mth, MethodGen mthGen) {
		if (mth.isNoCode()) {
			return Collections.emptyList();
		}

		ICodeWriter cw = mth.root().makeCodeWriter();
		try {
			mthGen.addInstructions(cw);
		} catch (Exception e) {
			throw new JadxRuntimeException("Method generation error", e);
		}
		ICodeInfo code = cw.finish();
		String codeStr = code.getCodeStr();
		if (codeStr.isEmpty()) {
			return Collections.emptyList();
		}

		String[] lines = codeStr.split(args.getCodeNewLineStr());
		Map<Integer, Integer> lineMapping = code.getCodeMetadata().getLineMapping();
		ICodeMetadata metadata = code.getCodeMetadata();
		long mthCodeOffset = mth.getMethodCodeOffset() + 16;

		int linesCount = lines.length;
		List<JsonCodeLine> codeLines = new ArrayList<>(linesCount);
		int lineStartPos = 0;
		int newLineLen = args.getCodeNewLineStr().length();
		for (int i = 0; i < linesCount; i++) {
			String codeLine = lines[i];

View on GitHub (pinned to e738a26571)

Solutions

  1. Read the caused-by (e.getCause()) exception - that identifies the actual failure (e.g. one of the other RegionGen/TypeGen errors).
  2. Fix the underlying codegen problem for that method first.
  3. If the cause is unavoidable, wrap fillMthCode in a try/catch to emit an empty/partial method body and continue, instead of aborting the whole JSON dump.
  4. Update jadx; JSON codegen is under active development.

Example fix

// before
try {
    mthGen.addInstructions(cw);
} catch (Exception e) {
    throw new JadxRuntimeException("Method generation error", e);
}

// after (log and degrade instead of aborting the entire JSON export)
try {
    mthGen.addInstructions(cw);
} catch (Exception e) {
    LOG.warn("Failed to generate JSON code for {}", mth, e);
    return Collections.emptyList();
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (mth.isNoCode()) {
    return Collections.emptyList(); // no body to fail on
}

Type guard

null

Try / catch

List<JsonCodeLine> lines;
try {
    lines = fillMthCode(mth, mthGen);
} catch (JadxRuntimeException e) {
    LOG.warn("JSON codegen failed for {}: {}", mth, e.getCause() != null ? e.getCause() : e);
    lines = Collections.emptyList();
}

Prevention

When it happens

Trigger: Enabling JSON export (e.g. JadxArgs output mode or CLI flag that uses JsonCodeGen) and decompiling a method whose instruction emission throws any CodegenException or other exception. The real failure is in the underlying MethodGen; this exception merely wraps it.

Common situations: Using jadx as a library to export JSON mappings/source; CI pipelines that produce JSON for tooling; any input that already fails Java codegen will also fail here. The message is generic, so the caused-by exception is the real signal.

Related errors


AI-assisted analysis of skylot/jadx@e738a26571 (2026-08-14). Data as JSON: /api/errors/4be96bfabf9a1e96. Report an issue: GitHub.