{"record":{"id":"790c9d82739829eb","repo":"skylot/jadx","slug":"code-generation-error","errorCode":null,"errorMessage":"Code generation error","messagePattern":"Code generation error","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/codegen/CodeGen.java","lineNumber":55,"sourceCode":"\tprivate static ICodeInfo generateJson(ClassNode cls) {\n\t\tJsonCodeGen codeGen = new JsonCodeGen(cls);\n\t\tString clsJson = wrapCodeGen(cls, codeGen::process);\n\t\treturn new SimpleCodeInfo(clsJson);\n\t}\n\n\tprivate static <R> R wrapCodeGen(ClassNode cls, Callable<R> codeGenFunc) {\n\t\ttry {\n\t\t\treturn codeGenFunc.call();\n\t\t} catch (Exception e) {\n\t\t\tif (cls.contains(AFlag.RESTART_CODEGEN)) {\n\t\t\t\tcls.remove(AFlag.RESTART_CODEGEN);\n\t\t\t\ttry {\n\t\t\t\t\treturn codeGenFunc.call();\n\t\t\t\t} catch (Exception ex) {\n\t\t\t\t\tthrow new JadxRuntimeException(\"Code generation error after restart\", ex);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new JadxRuntimeException(\"Code generation error\", e);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate CodeGen() {\n\t}\n}\n","sourceCodeStart":37,"sourceCodeEnd":63,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/codegen/CodeGen.java#L37-L63","documentation":"Thrown by CodeGen.wrapCodeGen() on the first code generation failure when the RESTART_CODEGEN flag is not set on the class. This is the standard fatal path for any uncaught exception during makeClass() or JSON generation that has no recovery mechanism. The original exception is wrapped as the cause.","triggerScenarios":"Any exception thrown during ClassGen.makeClass() or JsonCodeGen.process() where the class does not have RESTART_CODEGEN set. This is the catch-all for code generation failures that are not eligible for the restart recovery path.","commonSituations":"Unhandled instruction types, unexpected null references, or logic errors during class code generation. Corrupted or unusual bytecode that triggers an uncaught exception.","solutions":["Examine the wrapped cause exception — it contains the actual failure point and is the primary diagnostic.","Report the class and stack trace to the jadx issue tracker.","Try DecompilationMode.FALLBACK or exclude the class."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Validate class is processable before codegen\nif (cls.contains(AFlag.DONT_GENERATE)) {\n    return; // skip\n}\n// Use try-with-error-collection per class\ntry {\n    codeGen.makeCode(cls);\n} catch (JadxRuntimeException e) {\n    cls.addError(\"Code generation error\", e);\n    // continue with other classes instead of aborting the batch\n}","typeGuard":null,"tryCatchPattern":"try {\n    ICodeInfo code = CodeGen.makeCode(cls);\n} catch (JadxRuntimeException e) {\n    if (e.getMessage().equals(\"Code generation error\")) {\n        Throwable cause = e.getCause();\n        logger.error(\"Failed to generate code for class {}: {}\",\n            cls.getClassInfo().getFullName(), cause.getMessage(), e);\n        cls.addError(\"Code generation error\", cause);\n        // Continue with other classes\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always examine the wrapped cause exception — it has the actual failure.","Process classes individually and catch exceptions per-class to avoid batch failures.","Use fallback decompilation mode for classes that consistently fail."],"tags":["codegen","catch-all","decompiler-bug"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}