{"record":{"id":"54812d1c804f3fc1","repo":"skylot/jadx","slug":"incorrect-negative-register-number-in-instruction","errorCode":null,"errorMessage":"Incorrect negative register number in instruction: {}","messagePattern":"Incorrect negative register number in instruction: (.+?)","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/dex/visitors/CheckCode.java","lineNumber":76,"sourceCode":"\t\tif (isEmpty(mth.getInstructions())) {\n\t\t\treturn;\n\t\t}\n\t\tint regsCount = mth.getRegsCount();\n\t\tList<RegisterArg> list = new ArrayList<>();\n\t\tfor (InsnNode insnNode : mth.getInstructions()) {\n\t\t\tif (insnNode == null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlist.clear();\n\t\t\tRegisterArg resultArg = insnNode.getResult();\n\t\t\tif (resultArg != null) {\n\t\t\t\tlist.add(resultArg);\n\t\t\t}\n\t\t\tinsnNode.getRegisterArgs(list);\n\t\t\tfor (RegisterArg arg : list) {\n\t\t\t\tint regNum = arg.getRegNum();\n\t\t\t\tif (regNum < 0) {\n\t\t\t\t\tthrow new JadxRuntimeException(\"Incorrect negative register number in instruction: \" + insnNode);\n\t\t\t\t}\n\t\t\t\tif (regNum >= regsCount) {\n\t\t\t\t\tthrow new JadxRuntimeException(\"Incorrect register number in instruction: \" + insnNode\n\t\t\t\t\t\t\t+ \", expected to be less than \" + regsCount);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n","sourceCodeStart":58,"sourceCodeEnd":86,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/dex/visitors/CheckCode.java#L58-L86","documentation":"Thrown by CheckCode.checkInstructions() when iterating every register referenced by an instruction and finding one whose register number is negative. Register numbers must be non-negative integers in valid Dalvik bytecode; a negative value indicates the instruction was built incorrectly during earlier decoding or that the DEX file is corrupt.","triggerScenarios":"CheckCode.visit() runs on a MethodNode, iterates mth.getInstructions(), collects result + source register args, and for some RegisterArg arg.getRegNum() < 0. This can happen if a register arg was created with an unset/default register number, or if a bytecode rewriter emitted an instruction with a malformed register operand.","commonSituations":"Corrupt or tampered DEX files, DEX produced by non-standard tools, or edge cases where jadx's own instruction decoder mis-parses a register slot. Rare with output from standard Android build tools (d8/r8).","solutions":["Upgrade jadx — instruction decoding and register handling are regularly fixed.","Catch JadxRuntimeException around per-class decompilation to avoid aborting the whole batch.","Report the issue with the instruction dump from the error message and the offending DEX.","If the DEX is corrupt, re-verify with dexdump or baksmali and obtain a non-corrupt copy."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Basic DEX integrity sanity check before decompiling\nimport java.io.File;\nimport java.io.FileInputStream;\n\nboolean looksLikeValidDex(File f) throws IOException {\n    try (FileInputStream fis = new FileInputStream(f)) {\n        byte[] magic = new byte[8];\n        if (fis.read(magic) < 8) return false;\n        // DEX magic: 'dex\\n' followed by version and '\\0'\n        return magic[0] == 'd' && magic[1] == 'e' && magic[2] == 'x' && magic[3] == '\\n';\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    jadx.load();\n    jadx.save();\n} catch (JadxRuntimeException e) {\n    // Catch at the batch level; consider per-class fallback\n    LOG.error(\"Decompilation failed (register validation): {}\", e.getMessage());\n}","preventionTips":["Validate input DEX files with dexdump --verify before decompiling.","Use original APKs/DEX from trusted build tools; avoid re-processed or tampered files.","Upgrade jadx for instruction-decoder fixes.","Process per-class with try-catch to isolate corrupt methods."],"tags":["jadx","decompiler","register-validation","bytecode","dex","code-check"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}