{"record":{"id":"9e79637db162e948","repo":"pxb1988/dex2jar","slug":"invalid-ret-type","errorCode":null,"errorMessage":"invalid ret type:","messagePattern":"invalid ret type:","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"dex-tools/src/main/java/com/googlecode/d2j/tools/jar/InvocationWeaver.java","lineNumber":169,"sourceCode":"                break;\n            case Type.BYTE:\n                mv.visitMethodInsn(INVOKESTATIC, \"java/lang/Byte\", \"valueOf\", \"(B)Ljava/lang/Byte;\", false);\n                break;\n            case Type.VOID:\n                mv.visitInsn(ACONST_NULL);\n                break;\n        }\n    }\n\n    static private void unBox(Type orgRet, Type nRet, MethodVisitor mv) {\n        if (orgRet.equals(nRet)) {\n            return;\n        }\n        if (orgRet.getSort() == Type.VOID) {\n            mv.visitInsn(nRet.getSize() == 1 ? POP : POP2);\n        }\n        if (nRet.getSort() != Type.OBJECT) {\n            throw new RuntimeException(\"invalid ret type:\" + nRet);\n        }\n        switch (orgRet.getSort()) {\n            case Type.OBJECT:\n            case Type.ARRAY:\n                mv.visitTypeInsn(CHECKCAST, orgRet.getInternalName());\n                break;\n            case Type.INT:\n                mv.visitTypeInsn(CHECKCAST, \"java/lang/Number\");\n                mv.visitMethodInsn(INVOKEVIRTUAL, \"java/lang/Number\", \"intValue\", \"()I\", false);\n                break;\n            case Type.FLOAT:\n                mv.visitTypeInsn(CHECKCAST, \"java/lang/Number\");\n                mv.visitMethodInsn(INVOKEVIRTUAL, \"java/lang/Number\", \"floatValue\", \"()F\", false);\n                break;\n            case Type.LONG:\n                mv.visitTypeInsn(CHECKCAST, \"java/lang/Number\");\n                mv.visitMethodInsn(INVOKEVIRTUAL, \"java/lang/Number\", \"longValue\", \"()J\", false);\n                break;","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-tools/src/main/java/com/googlecode/d2j/tools/jar/InvocationWeaver.java#L151-L187","documentation":"Thrown by InvocationWeaver.unBox after generating the callback invocation: after the mapped method's return value is handled (void results are POP/POP2-ed), the new (mapped) return type must be an OBJECT sort so unboxing/conversion logic can proceed. A primitive or ARRAY new return type indicates the weaver cannot convert the replacement method's return value to the original method's return type.","triggerScenarios":"Configuring a method mapping whose replacement (mapTo) returns a primitive type (e.g. I, J, Z) or array sort instead of an object type, then running the weaver via genMethodACode or newMethodCallback while the original method's return is non-void.","commonSituations":"Writing a transform config that replaces a method returning java.lang.Integer/object with one returning int, or mapping a method whose return type was authored with the wrong descriptor in the weaving configuration.","solutions":["Fix the mapping configuration so the replacement method's return type is an object type compatible with the original return type.","If a primitive result is needed, wrap it: return java/lang/Integer and let the original descriptor's unboxing path convert it.","If the original return should be ignored, change the mapping so the original return type is void rather than making the new return primitive.","Check the descriptor of mapTo in the config for typos (e.g. ')I' vs ')Ljava/lang/Integer;')."],"exampleFix":"// before (mapping config)\nret = I\n// after\nret = Ljava/lang/Integer;","handlingStrategy":"validation","validationCode":"// validate the mapping before weaving\nType nRet = Type.getReturnType(mapTo.desc);\nif (nRet.getSort() != Type.OBJECT && nRet.getSort() != Type.VOID) {\n    throw new IllegalArgumentException(\"mapTo must return an object type, got: \" + nRet);\n}","typeGuard":null,"tryCatchPattern":"try {\n    new InvocationWeaver(cfg).weave();\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"invalid ret type\")) {\n        throw new IllegalStateException(\"Fix the mapping: replacement method must return an object type\", e);\n    }\n    throw e;\n}","preventionTips":["Box primitive returns (int -> java/lang/Integer) in replacement methods","Validate mapping descriptors with Type.getReturnType before running the weaver","Keep mapTo signatures synchronized with the original API after refactors"],"tags":["bytecode","weaving","type-mismatch"],"backgroundTag":"incompatible-source-type","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}