{"record":{"id":"05fe60a67ba50ee7","repo":"skylot/jadx","slug":"code-generation-error-after-restart","errorCode":null,"errorMessage":"Code generation error after restart","messagePattern":"Code generation error after restart","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/codegen/CodeGen.java","lineNumber":52,"sourceCode":"\t\treturn wrapCodeGen(cls, clsGen::makeClass);\n\t}\n\n\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":34,"sourceCodeEnd":63,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/codegen/CodeGen.java#L34-L63","documentation":"Thrown by CodeGen.wrapCodeGen() when a second attempt at code generation also fails. The method first tries codeGenFunc.call(); on exception, if RESTART_CODEGEN is set, it removes the flag and retries. If the retry also throws, it wraps the second exception in a JadxRuntimeException with this message. This is the terminal failure after the anonymous-class-inlining recovery path has been exhausted.","triggerScenarios":"Anonymous class inlining triggers RESTART_CODEGEN, the class codegen restarts, and the restart attempt also encounters an exception. The original exception from the first attempt is lost; only the second (restart) exception is captured.","commonSituations":"Complex nested anonymous classes where the conversion-to-inner-class recovery still cannot generate valid code. Obfuscated code with unusual constructor or lambda patterns.","solutions":["Report the class to the jadx project with the full stack trace (the inner cause exception is the key diagnostic).","Switch to DecompilationMode.FALLBACK which bypasses many of the aggressive transforms that trigger restarts.","Exclude the problematic class from decompilation."],"exampleFix":"// before\n//   JadxArgs args = new JadxArgs();\n//   args.setDecompilationMode(DecompilationMode.AUTO);\n// after\n//   args.setDecompilationMode(DecompilationMode.FALLBACK);","handlingStrategy":"fallback","validationCode":"// Set fallback mode to avoid the restart-triggering code paths\nJadxArgs args = new JadxArgs();\nargs.setDecompilationMode(DecompilationMode.FALLBACK);\n// This bypasses anonymous class inlining that causes RESTART_CODEGEN","typeGuard":null,"tryCatchPattern":"try {\n    jadxDecompiler.decompile();\n} catch (JadxRuntimeException e) {\n    if (e.getMessage().equals(\"Code generation error after restart\")) {\n        logger.error(\"Codegen failed after restart. The cause exception has the root failure.\", e);\n        // Examine e.getCause() for the actual failure on the second attempt\n    }\n    throw e;\n}","preventionTips":["Examine the cause exception — it contains the real failure from the restart attempt.","Use DecompilationMode.FALLBACK for classes that trigger restart failures.","Report classes with anonymous-class recursion to the jadx project."],"tags":["codegen","restart","anonymous-class","decompiler-bug"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}