{"record":{"id":"7797cbdb94c91a1e","repo":"skylot/jadx","slug":"failed-to-replace-insn","errorCode":null,"errorMessage":"Failed to replace insn","messagePattern":"Failed to replace insn","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java","lineNumber":93,"sourceCode":"\t\tif (changed || mth.contains(AFlag.REQUEST_CODE_SHRINK)) {\n\t\t\tCodeShrinkVisitor.shrinkMethod(mth);\n\t\t}\n\t}\n\n\tprivate boolean simplifyBlock(MethodNode mth, BlockNode block) {\n\t\tboolean changed = false;\n\t\tList<InsnNode> list = block.getInstructions();\n\t\tfor (int i = 0; i < list.size(); i++) {\n\t\t\tInsnNode insn = list.get(i);\n\t\t\tint insnCount = list.size();\n\t\t\tInsnNode modInsn = simplifyInsn(mth, insn, null);\n\t\t\tif (modInsn != null) {\n\t\t\t\tif (i < list.size() && list.get(i) == insn) {\n\t\t\t\t\tlist.set(i, modInsn);\n\t\t\t\t} else {\n\t\t\t\t\tint idx = InsnList.getIndex(list, insn);\n\t\t\t\t\tif (idx == -1) {\n\t\t\t\t\t\tthrow new JadxRuntimeException(\"Failed to replace insn\");\n\t\t\t\t\t}\n\t\t\t\t\tlist.set(idx, modInsn);\n\t\t\t\t}\n\t\t\t\tInsnRemover.unbindInsn(mth, insn);\n\t\t\t\tmodInsn.rebindArgs();\n\t\t\t\tif (list.size() < insnCount) {\n\t\t\t\t\t// some insns removed => restart block processing\n\t\t\t\t\tsimplifyBlock(mth, block);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\t\treturn changed;\n\t}\n\n\tprivate void simplifyArgs(MethodNode mth, InsnNode insn) {\n\t\tboolean changed = false;","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java#L75-L111","documentation":"Thrown during SimplifyVisitor's block simplification pass when a simplified instruction cannot be found in the block's instruction list to be replaced. The visitor calls simplifyInsn, which may recursively simplify and modify the list. By the time it tries to replace the original instruction, the list may have changed. If the original instruction is no longer at the expected index and InsnList.getIndex also fails, the replacement is impossible.","triggerScenarios":"A recursive simplifyInsn call removes or replaces the original instruction (or instructions around it) from the list before the outer replace call executes. The list.size() check and index-based lookup both miss, confirming the instruction was consumed by a nested simplification.","commonSituations":"Complex instruction chains where one simplification cascades into others (e.g., a series of move/const/arithmetic instructions that collapse together); deeply nested ternary or string concatenation patterns that trigger aggressive simplification.","solutions":["Update jadx — the simplify pass is frequently patched for cascade edge cases","Report the failing method/class as a jadx issue with the input APK","Try disabling specific simplification passes via command-line flags if available","As a workaround, use --no-replace-consts to reduce simplification aggressiveness"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    jadxDecompiler.load();\n    jadxDecompiler.save();\n} catch (JadxRuntimeException e) {\n    if (e.getMessage().contains(\"Failed to replace insn\")) {\n        LOG.warn(\"Simplification cascade issue, retrying with --no-replace-consts\");\n        args.setReplaceConsts(false);\n        jadxDecompiler = new JadxDecompiler(args);\n        jadxDecompiler.load();\n        jadxDecompiler.save();\n    } else {\n        throw e;\n    }\n}","preventionTips":["Keep jadx updated — the SimplifyVisitor cascade handling is frequently patched","Try --no-replace-consts to reduce simplification aggressiveness","Report the failing method/APK as a jadx issue with the full stack trace","Use per-class decompilation to isolate the trigger"],"tags":["simplification","instruction-processing","cascade","decompiler"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}