{"record":{"id":"cb11ee912bdf41a5","repo":"Tencent/APIJSON","slug":"methodname-rt-null-cb11ee","errorCode":null,"errorMessage":"远程函数 \" + methodName + \" 的实际返回值类型 \" + (rt == null ? null : rt.getName()) + \" 与 Function 表中的配置的 \" + returnType + \" 对应的 \" + fullReturnType + \" 不匹配！","messagePattern":"远程函数 \" \\+ methodName \\+ \" 的实际返回值类型 \" \\+ \\(rt == null \\? null : rt\\.getName\\(\\)\\) \\+ \" 与 Function 表中的配置的 \" \\+ returnType \\+ \" 对应的 \" \\+ fullReturnType \\+ \" 不匹配！","errorType":"exception","errorClass":"WrongMethodTypeException","httpStatus":null,"severity":"warning","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java","lineNumber":558,"sourceCode":"            String fullReturnType = (StringUtil.isSmallName(returnType)\n                    ? returnType : (returnType.startsWith(\"JSON\") ? \"com.alibaba.fastjson.\" : \"java.lang.\") + returnType);\n\n            if ((rt == null && returnType != null) || (rt != null && returnType == null)) {\n                throw new WrongMethodTypeException(\"远程函数 \" + methodName + \" 的实际返回值类型 \"\n                        + (rt == null ? null : rt.getName()) + \" 与 Function 表中的配置的 \" + fullReturnType + \" 不匹配！\");\n            }\n\n            Class<?> cls;\n            try {\n                cls = Class.forName(fullReturnType);\n            }\n            catch (Exception e) {\n                throw new WrongMethodTypeException(\"远程函数 \" + methodName + \" 在 Function 表中的配置的类型 \"\n                        + returnType + \" 对应的 \" + fullReturnType + \" 错误！在 Java 中 Class.forName 找不到这个类型！\");\n            }\n\n            if (cls.isAssignableFrom(rt) == false) {\n                throw new WrongMethodTypeException(\"远程函数 \" + methodName + \" 的实际返回值类型 \"\n                        + (rt == null ? null : rt.getName()) + \" 与 Function 表中的配置的 \"\n                        + returnType + \" 对应的 \" + fullReturnType + \" 不匹配！\");\n            }\n        }\n\n        Log.d(TAG, \"invokeScript \" + methodName + \"(..) >>  result = \" + result);\n        return result;\n    }\n\n\n    /**解析函数\n     * @param function\n     * @param request\n     * @param isSQLFunction\n     * @return\n     * @throws Exception\n     */\n\t@NotNull","sourceCodeStart":540,"sourceCodeEnd":576,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java#L540-L576","documentation":"Final debug-mode check in invokeScript: the configured returnType resolves to a class, but the script result's runtime class is not assignable to it (cls.isAssignableFrom(rt) fails), so WrongMethodTypeException is thrown. This catches scripts returning a different JSON type than promised, e.g. a string where the table says Number.","triggerScenarios":"Function row language='javascript', returnType='Number', but the JS function returns a string or an object/array; only evaluated when Log.DEBUG is true and the result is non-null.","commonSituations":"JS number formatting returns \"123\" instead of 123; script refactored to return an object while the table still declares a primitive name; fastjson types returned where java.lang types configured.","solutions":["Make the script return the exact configured type (convert with Number(), String(), Boolean() in JS).","Or update the Function row's returnType to the type the script actually returns.","For collection results, use the matching fastjson type names (JSONObject/JSONArray) in the table."],"exampleFix":"// before: returnType='Number'\nfunction enc(x) { return \"ID-\" + x; } // returns string\n\n// after\nfunction enc(x) { return x + 1; } // returns number  -- or set returnType='String'","handlingStrategy":"validation","validationCode":"Object result = scriptExecutor.execute(...);\nClass<?> rt = result.getClass();\nClass<?> cls = Class.forName(fullReturnType);\nif (!cls.isAssignableFrom(rt)) { /* script returned different type than configured: coerce in script or fix row */ }","typeGuard":"public static boolean resultMatchesConfig(Object result, Class<?> configured) {\n    return result == null || configured == null || configured.isAssignableFrom(result.getClass());\n}","tryCatchPattern":"try { invokeScript(...); } catch (WrongMethodTypeException e) { if (e.getMessage().contains(\"isAssignableFrom\") || e.getMessage().contains(\"不匹配\")) { /* coerce script return type or update returnType */ } throw e; }","preventionTips":["End scripts with explicit type conversion (Number(x), String(x), Boolean(x)) matching the table.","Keep a typed contract test per script function.","Remember JS numbers may arrive as Integer/Long/Double — pick Number in the table for numeric returns."],"tags":["apijson","scripting","return-type","type-mismatch","debug"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}