{"record":{"id":"66fd48082eeb9a7e","repo":"skylot/jadx","slug":"incorrect-nodes-count-for-selectother-in","errorCode":null,"errorMessage":"Incorrect nodes count for selectOther: {} in {}","messagePattern":"Incorrect nodes count for selectOther: (.+?) in (.+?)","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/utils/BlockUtils.java","lineNumber":68,"sourceCode":"\n\tpublic static BlockNode getBlockByOffset(int offset, Iterable<BlockNode> casesBlocks) {\n\t\tfor (BlockNode block : casesBlocks) {\n\t\t\tif (block.getStartOffset() == offset) {\n\t\t\t\treturn block;\n\t\t\t}\n\t\t}\n\t\tthrow new JadxRuntimeException(\"Can't find block by offset: \"\n\t\t\t\t+ InsnUtils.formatOffset(offset)\n\t\t\t\t+ \" in list \" + casesBlocks);\n\t}\n\n\tpublic static BlockNode selectOther(BlockNode node, List<BlockNode> blocks) {\n\t\tList<BlockNode> list = blocks;\n\t\tif (list.size() > 2) {\n\t\t\tlist = cleanBlockList(list);\n\t\t}\n\t\tif (list.size() != 2) {\n\t\t\tthrow new JadxRuntimeException(\"Incorrect nodes count for selectOther: \" + node + \" in \" + list);\n\t\t}\n\t\tBlockNode first = list.get(0);\n\t\tif (first != node) {\n\t\t\treturn first;\n\t\t} else {\n\t\t\treturn list.get(1);\n\t\t}\n\t}\n\n\tpublic static BlockNode selectOtherSafe(BlockNode node, List<BlockNode> blocks) {\n\t\tint size = blocks.size();\n\t\tif (size == 1) {\n\t\t\tBlockNode first = blocks.get(0);\n\t\t\treturn first != node ? first : null;\n\t\t}\n\t\tif (size == 2) {\n\t\t\tBlockNode first = blocks.get(0);\n\t\t\treturn first != node ? first : blocks.get(1);","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/utils/BlockUtils.java#L50-L86","documentation":"Thrown by BlockUtils.selectOther when, after optionally cleaning a >2 list, the list does not contain exactly two blocks. selectOther is the helper used by IfNode/ResolveJavaJSR/LoopInfo to pick 'the other' branch of a binary split, so it assumes exactly two candidates. Failure indicates the input list was not a binary branch (size 0, 1, 3+, or a list that cleanBlockList could not reduce).","triggerScenarios":"Calling selectOther(node, blocks) on a successors/predecessors list that is not a binary branch - e.g. an if-instruction with one target (degenerate), a block with three successors passed where two were expected, or a list whose entries are filtered away by cleanBlockList.","commonSituations":"Reachable from IfNode (which expects exactly then/else), LoopInfo (loop end vs. pre-header), and ResolveJavaJSR. Usually a symptom of a malformed CFG built earlier in the pipeline rather than a problem with your input per se.","solutions":["Update jadx; CFG/branch-shape assumptions are tuned over releases.","Report the method/class with the offending node and list from the message.","Use selectOtherSafe (which returns null instead of throwing) if you are calling BlockUtils directly in a plugin/pass and can tolerate a non-binary branch.","Catch JadxRuntimeException per method when embedding jadx."],"exampleFix":"// before - throws on non-binary lists\nBlockNode other = BlockUtils.selectOther(node, blocks);\n// after - tolerate non-binary shape\nBlockNode other = BlockUtils.selectOtherSafe(node, blocks);","handlingStrategy":"try-catch","validationCode":"// pre-check before calling selectOther\nList<BlockNode> l = blocks.size() > 2 ? cleanBlockList(blocks) : blocks;\nif (l.size() == 2) {\n    BlockNode other = BlockUtils.selectOther(node, l);\n}","typeGuard":null,"tryCatchPattern":"BlockNode other;\ntry {\n    other = BlockUtils.selectOther(node, blocks);\n} catch (JadxRuntimeException e) {\n    other = null; // not a binary branch\n}","preventionTips":["Prefer BlockUtils.selectOtherSafe (returns null) when you can tolerate a non-binary branch.","If you call selectOther directly, ensure the list is a binary branch first.","Update jadx; CFG shape assumptions are tuned over releases."],"tags":["decompiler","blocks","control-flow","branches","invariant-violation"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}