{"record":{"id":"4be96bfabf9a1e96","repo":"skylot/jadx","slug":"method-generation-error-4be96b","errorCode":null,"errorMessage":"Method generation error","messagePattern":"Method generation error","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/codegen/json/JsonCodeGen.java","lineNumber":175,"sourceCode":"\t\t\tmthGen.addDefinition(cw);\n\t\t\tjsonMth.setDeclaration(cw.getCodeStr());\n\t\t\tjsonMth.setAccessFlags(mth.getAccessFlags().rawValue());\n\t\t\tjsonMth.setLines(fillMthCode(mth, mthGen));\n\t\t\tjsonMth.setOffset(\"0x\" + Long.toHexString(mth.getMethodCodeOffset()));\n\t\t\tjsonCls.getMethods().add(jsonMth);\n\t\t}\n\t}\n\n\tprivate List<JsonCodeLine> fillMthCode(MethodNode mth, MethodGen mthGen) {\n\t\tif (mth.isNoCode()) {\n\t\t\treturn Collections.emptyList();\n\t\t}\n\n\t\tICodeWriter cw = mth.root().makeCodeWriter();\n\t\ttry {\n\t\t\tmthGen.addInstructions(cw);\n\t\t} catch (Exception e) {\n\t\t\tthrow new JadxRuntimeException(\"Method generation error\", e);\n\t\t}\n\t\tICodeInfo code = cw.finish();\n\t\tString codeStr = code.getCodeStr();\n\t\tif (codeStr.isEmpty()) {\n\t\t\treturn Collections.emptyList();\n\t\t}\n\n\t\tString[] lines = codeStr.split(args.getCodeNewLineStr());\n\t\tMap<Integer, Integer> lineMapping = code.getCodeMetadata().getLineMapping();\n\t\tICodeMetadata metadata = code.getCodeMetadata();\n\t\tlong mthCodeOffset = mth.getMethodCodeOffset() + 16;\n\n\t\tint linesCount = lines.length;\n\t\tList<JsonCodeLine> codeLines = new ArrayList<>(linesCount);\n\t\tint lineStartPos = 0;\n\t\tint newLineLen = args.getCodeNewLineStr().length();\n\t\tfor (int i = 0; i < linesCount; i++) {\n\t\t\tString codeLine = lines[i];","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/codegen/json/JsonCodeGen.java#L157-L193","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the caused-by (e.getCause()) exception - that identifies the actual failure (e.g. one of the other RegionGen/TypeGen errors).","Fix the underlying codegen problem for that method first.","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.","Update jadx; JSON codegen is under active development."],"exampleFix":"// before\ntry {\n    mthGen.addInstructions(cw);\n} catch (Exception e) {\n    throw new JadxRuntimeException(\"Method generation error\", e);\n}\n\n// after (log and degrade instead of aborting the entire JSON export)\ntry {\n    mthGen.addInstructions(cw);\n} catch (Exception e) {\n    LOG.warn(\"Failed to generate JSON code for {}\", mth, e);\n    return Collections.emptyList();\n}","handlingStrategy":"try-catch","validationCode":"if (mth.isNoCode()) {\n    return Collections.emptyList(); // no body to fail on\n}","typeGuard":"null","tryCatchPattern":"List<JsonCodeLine> lines;\ntry {\n    lines = fillMthCode(mth, mthGen);\n} catch (JadxRuntimeException e) {\n    LOG.warn(\"JSON codegen failed for {}: {}\", mth, e.getCause() != null ? e.getCause() : e);\n    lines = Collections.emptyList();\n}","preventionTips":["Always inspect getCause() - the real failure is wrapped.","Treat JSON export as best-effort: a single method failure should not abort the whole dump.","Resolve underlying Java-codegen errors before relying on JSON output."],"tags":["json","codegen","wrapper","io"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}