{"record":{"id":"f4999f708766b87e","repo":"skylot/jadx","slug":"unexpected-instance-arg-in-invoke","errorCode":null,"errorMessage":"Unexpected instance arg in invoke","messagePattern":"Unexpected instance arg in invoke","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlineVisitor.java","lineNumber":285,"sourceCode":"\t\t\t\taddExplicitCast(useInsn, litArg);\n\t\t\t}\n\t\t} else {\n\t\t\tif (!useInsn.replaceArg(arg, constArg.duplicate())) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\tuseInsn.inheritMetadata(constInsn);\n\t\treturn true;\n\t}\n\n\tprivate static void addExplicitCast(InsnNode insn, LiteralArg arg) {\n\t\tif (insn instanceof BaseInvokeNode) {\n\t\t\tBaseInvokeNode callInsn = (BaseInvokeNode) insn;\n\t\t\tMethodInfo callMth = callInsn.getCallMth();\n\t\t\tif (callInsn.getInstanceArg() == arg) {\n\t\t\t\t// instance arg is null, force cast\n\t\t\t\tif (!arg.isZeroLiteral()) {\n\t\t\t\t\tthrow new JadxRuntimeException(\"Unexpected instance arg in invoke\");\n\t\t\t\t}\n\t\t\t\tArgType castType = callMth.getDeclClass().getType();\n\t\t\t\tInsnNode castInsn = new IndexInsnNode(InsnType.CAST, castType, 1);\n\t\t\t\tcastInsn.addArg(arg);\n\t\t\t\tcastInsn.add(AFlag.EXPLICIT_CAST);\n\t\t\t\tInsnArg wrapCast = InsnArg.wrapArg(castInsn);\n\t\t\t\twrapCast.setType(castType);\n\t\t\t\tinsn.replaceArg(arg, wrapCast);\n\t\t\t} else {\n\t\t\t\tint offset = callInsn.getFirstArgOffset();\n\t\t\t\tint argIndex = insn.getArgIndex(arg);\n\t\t\t\tArgType argType = callMth.getArgumentsTypes().get(argIndex - offset);\n\t\t\t\tif (argType.isPrimitive()) {\n\t\t\t\t\targ.setType(argType);\n\t\t\t\t\tif (argType.equals(ArgType.BYTE)) {\n\t\t\t\t\t\targ.add(AFlag.EXPLICIT_PRIMITIVE_TYPE);\n\t\t\t\t\t}\n\t\t\t\t}","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlineVisitor.java#L267-L303","documentation":"Thrown by ConstInlineVisitor.addExplicitCast() when a constant being inlined lands in the instance-argument slot of an invoke instruction but the literal value is not zero. The code only handles the case where the instance arg is null (zero literal), inserting a cast; a non-zero literal as an instance arg is an unexpected state that would produce semantically wrong code, so jadx aborts.","triggerScenarios":"During const inlining, addExplicitCast() is called on a BaseInvokeNode. callInsn.getInstanceArg() == arg (the inlined const is the instance arg), but arg.isZeroLiteral() is false. This means a non-null constant was used where an object instance reference is expected — an inconsistent state from prior visitor passes.","commonSituations":"Complex bytecode where constant propagation interacts with invoke instructions in unusual ways, typically from heavily optimised or obfuscated code. Can also arise from bugs in earlier visitor passes that mis-type an argument.","solutions":["Upgrade jadx — const-inlining logic is refined across releases.","Disable const inlining via jadx args (set fallback options or use --no-debug-info / conservative mode) to avoid the visitor triggering.","Catch JadxRuntimeException per class/method and skip.","Report the issue with the instruction and call method info from the error context."],"exampleFix":"// before — default settings trigger const inline visitor\nJadxArgs args = new JadxArgs();\nargs.setInputFiles(Arrays.asList(file));\n\n// after — disable the visitor to avoid the crash\nargs.setRunFinalDecompiler(false); // or disable specific visitors via args flags\n// Catch and skip the class as a safety net","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    javaClass.decompile();\n} catch (JadxRuntimeException e) {\n    LOG.warn(\"Const-inline failure in {}: {}\", javaClass.getName(), e.getMessage());\n    // Fall back: re-decompile with const inlining disabled\n}","preventionTips":["Upgrade jadx — const-inlining heuristics improve regularly.","If the error recurs on the same class, try disabling const inlining via JadxArgs or CLI flags.","Isolate per-class failures with try-catch.","Report the failing instruction context to the jadx project."],"tags":["jadx","decompiler","const-inline","invoke","type-cast","optimization"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}