{"record":{"id":"16a0a5ba03fbfb0b","repo":"skylot/jadx","slug":"insn-not-found-in-method","errorCode":null,"errorMessage":"Insn not found in method: {}","messagePattern":"Insn not found in method: (.+?)","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/utils/BlockUtils.java","lineNumber":1381,"sourceCode":"\t\t\t\treturn null;\n\t\t\t}\n\t\t\tif (insn != null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tinsn = blockInsns.get(0);\n\t\t}\n\t\treturn insn;\n\t}\n\n\tpublic static boolean isFirstInsn(MethodNode mth, InsnNode insn) {\n\t\tBlockNode startBlock = followEmptyPath(mth.getEnterBlock());\n\t\tif (startBlock != null && !startBlock.getInstructions().isEmpty()) {\n\t\t\treturn startBlock.getInstructions().get(0) == insn;\n\t\t}\n\t\t// handle branching with empty blocks\n\t\tBlockNode block = getBlockByInsn(mth, insn);\n\t\tif (block == null) {\n\t\t\tthrow new JadxRuntimeException(\"Insn not found in method: \" + insn);\n\t\t}\n\t\tif (block.getInstructions().get(0) != insn) {\n\t\t\treturn false;\n\t\t}\n\t\tSet<BlockNode> allPathsBlocks = getAllPathsBlocks(mth.getEnterBlock(), block);\n\t\tfor (BlockNode pathBlock : allPathsBlocks) {\n\t\t\tif (!pathBlock.getInstructions().isEmpty() && pathBlock != block) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Replace insn by index i in block,\n\t * for proper copy attributes, assume attributes are not overlap\n\t */\n\tpublic static void replaceInsn(MethodNode mth, BlockNode block, int i, InsnNode insn) {","sourceCodeStart":1363,"sourceCodeEnd":1399,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/utils/BlockUtils.java#L1363-L1399","documentation":"Thrown by BlockUtils.isFirstInsn when getBlockByInsn(mth, insn) returns null - i.e. the instruction is not present in any basic block of the method. isFirstInsn walks the enter block, then (if that is empty) looks up the instruction's block; if no block contains it, the lookup fails. It indicates the instruction was already removed, belongs to a different method, or is a synthetic with no placement.","triggerScenarios":"Calling isFirstInsn(mth, insn) with an InsnNode that is not in mth's basic blocks: an instruction removed by an earlier pass, an instruction constructed in a plugin but not inserted, or an instruction from a different MethodNode. The error names the offending instruction.","commonSituations":"Plugin/pass code that holds a stale InsnNode reference after a transform, or passes the wrong MethodNode. In jadx internals it can appear as a secondary effect of a pass that removed an instruction but did not invalidate callers holding the reference.","solutions":["Re-fetch the instruction from its block immediately before calling isFirstInsn, instead of caching the InsnNode across transforms.","Confirm the MethodNode argument is the one that actually owns the instruction.","If writing a plugin/pass, null-check getBlockByInsn(mth, insn) before calling isFirstInsn.","Update jadx and report the method if this fires from jadx's own passes."],"exampleFix":"// before\nif (BlockUtils.isFirstInsn(mth, maybeStaleInsn)) { ... }\n// after - re-resolve from the current block graph\nBlockNode b = BlockUtils.getBlockByInsn(mth, maybeStaleInsn);\nif (b != null && BlockUtils.isFirstInsn(mth, maybeStaleInsn)) { ... }","handlingStrategy":"validation","validationCode":"// confirm the insn still lives in the method before asking about it\nBlockNode b = BlockUtils.getBlockByInsn(mth, insn);\nif (b == null) {\n    // insn is not in mth - skip the isFirstInsn check\n    return false;\n}\nboolean first = BlockUtils.isFirstInsn(mth, insn);","typeGuard":null,"tryCatchPattern":"try {\n    return BlockUtils.isFirstInsn(mth, insn);\n} catch (JadxRuntimeException e) {\n    return false; // insn no longer in mth\n}","preventionTips":["Do not cache InsnNode references across passes that may remove them.","Re-resolve the insn's block with getBlockByInsn before calling isFirstInsn.","Make sure the MethodNode passed in actually owns the instruction."],"tags":["decompiler","blocks","instructions","invariant-violation","plugin-authoring"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}