{"record":{"id":"61940ab8c3018017","repo":"Tencent/tinker","slug":"switch-instruction-at-address-index-0x-x-d-refers","errorCode":null,"errorMessage":"Switch instruction at address/index 0x%x/%d refers to the wrong type of payload instruction.","messagePattern":"Switch instruction at address/index 0x%x/(.+?) refers to the wrong type of payload instruction\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"tinker-build/tinker-patch-lib/src/main/java/org/jf/dexlib2/builder/BuilderMutableMethodImplementation.java","lineNumber":490,"sourceCode":"                        BuilderInstruction targetInstruction = targetLocation.instruction;\n                        if (targetInstruction == null) {\n                            throw new IllegalStateException(String.format(\"Switch instruction at address/index \"\n                                    + \"0x%x/%d points to the end of the method.\", location.codeAddress, location.index));\n                        }\n\n                        if (targetInstruction.getOpcode() == Opcode.NOP) {\n                            targetInstruction = getFirstNonNop(targetLocation.index + 1);\n                        }\n                        if (targetInstruction == null || !(targetInstruction instanceof BuilderSwitchPayload)) {\n                            throw new IllegalStateException(String.format(\"Switch instruction at address/index \"\n                                            + \"0x%x/%d does not refer to a payload instruction.\",\n                                    location.codeAddress, location.index));\n                        }\n                        if ((instruction.opcode == Opcode.PACKED_SWITCH\n                                && targetInstruction.getOpcode() != Opcode.PACKED_SWITCH_PAYLOAD)\n                                || (instruction.opcode == Opcode.SPARSE_SWITCH\n                                        && targetInstruction.getOpcode() != Opcode.SPARSE_SWITCH_PAYLOAD)) {\n                            throw new IllegalStateException(String.format(\"Switch instruction at address/index \"\n                                            + \"0x%x/%d refers to the wrong type of payload instruction.\",\n                                    location.codeAddress, location.index));\n                        }\n\n                        if (!payloadLocations.add(targetLocation)) {\n                            throw new IllegalStateException(\"Multiple switch instructions refer to the same payload. \"\n                                    + \"This is not currently supported. Please file a bug :)\");\n                        }\n\n                        ((BuilderSwitchPayload) targetInstruction).referrer = location;\n                        break;\n                    }\n                    default: {\n                        break;\n                    }\n                }\n            }\n        }","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-build/tinker-patch-lib/src/main/java/org/jf/dexlib2/builder/BuilderMutableMethodImplementation.java#L472-L508","documentation":"dexlib2 validation error: the switch opcode and its payload opcode disagree — a PACKED_SWITCH must target a PACKED_SWITCH_PAYLOAD and SPARSE_SWITCH must target SPARSE_SWITCH_PAYLOAD. The dex violates this invariant, so dexlib2 refuses to rebuild the method.","triggerScenarios":"A dex where a packed-switch instruction's offset resolves to a sparse-switch payload (or vice versa), encountered while dexlib2 builds instructions during Tinker patch generation or application.","commonSituations":"Hand-crafted or obfuscator-generated dex that swaps payload types; tools that rewrite switch payloads without fixing the referring instruction; corrupted patch/dex files after bad transfers.","solutions":["Rebuild the offending dex from source without the tool that rewrites switch payloads","Upgrade the Tinker patch toolchain so its dexlib2 matches the dex producer","Verify patch file integrity (checksum/MD5) and re-download/regenerate if damaged"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    // patch generation / application over suspect dex\n} catch (IllegalStateException e) {\n    if (String.valueOf(e.getMessage()).contains(\"wrong type of payload\")) {\n        // mark dex invalid, exclude from patch scope\n    } else { throw e; }\n}","preventionTips":["Pin stable obfuscation tool versions across base and patch builds","Validate dex with dexdump --verify before including it in the patch pipeline"],"tags":["dexlib2","dex","switch-payload","malformed-dex","validation"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}