Tencent/APIJSON · warning · WrongMethodTypeException
远程函数 " + methodName + " 的实际返回值类型 " + (rt == null ? null : rt
Error message
远程函数 " + methodName + " 的实际返回值类型 " + (rt == null ? null : rt.getName()) + " 与 Function 表中的配置的 " + returnType + " 对应的 " + fullReturnType + " 不匹配!
What it means
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.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java:558
String fullReturnType = (StringUtil.isSmallName(returnType)
? returnType : (returnType.startsWith("JSON") ? "com.alibaba.fastjson." : "java.lang.") + returnType);
if ((rt == null && returnType != null) || (rt != null && returnType == null)) {
throw new WrongMethodTypeException("远程函数 " + methodName + " 的实际返回值类型 "
+ (rt == null ? null : rt.getName()) + " 与 Function 表中的配置的 " + fullReturnType + " 不匹配!");
}
Class<?> cls;
try {
cls = Class.forName(fullReturnType);
}
catch (Exception e) {
throw new WrongMethodTypeException("远程函数 " + methodName + " 在 Function 表中的配置的类型 "
+ returnType + " 对应的 " + fullReturnType + " 错误!在 Java 中 Class.forName 找不到这个类型!");
}
if (cls.isAssignableFrom(rt) == false) {
throw new WrongMethodTypeException("远程函数 " + methodName + " 的实际返回值类型 "
+ (rt == null ? null : rt.getName()) + " 与 Function 表中的配置的 "
+ returnType + " 对应的 " + fullReturnType + " 不匹配!");
}
}
Log.d(TAG, "invokeScript " + methodName + "(..) >> result = " + result);
return result;
}
/**解析函数
* @param function
* @param request
* @param isSQLFunction
* @return
* @throws Exception
*/
@NotNullView on GitHub (pinned to 5284052872)
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.
Example fix
// before: returnType='Number'
function enc(x) { return "ID-" + x; } // returns string
// after
function enc(x) { return x + 1; } // returns number -- or set returnType='String' Defensive patterns
Strategy: validation
Validate before calling
Object result = scriptExecutor.execute(...);
Class<?> rt = result.getClass();
Class<?> cls = Class.forName(fullReturnType);
if (!cls.isAssignableFrom(rt)) { /* script returned different type than configured: coerce in script or fix row */ } Type guard
public static boolean resultMatchesConfig(Object result, Class<?> configured) {
return result == null || configured == null || configured.isAssignableFrom(result.getClass());
} Try / catch
try { invokeScript(...); } catch (WrongMethodTypeException e) { if (e.getMessage().contains("isAssignableFrom") || e.getMessage().contains("不匹配")) { /* coerce script return type or update returnType */ } throw e; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 远程函数 " + methodName + " 的实际返回值类型 " + (rt == null ? null : rt
- 远程函数 " + methodName + " 的实际返回值类型 " + rt + " 与 Function 表中的配置
- 远程函数 " + methodName + " 在 Function 表中的配置的类型 " + returnType +
- language = " + language + " 不合法!AbstractFunctionParser.ENABL
- 找不到脚本语言 " + lang + " 对应的执行引擎!请先依赖相关库并在后端 APIJSONFunctionPars
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/cb11ee912bdf41a5.
Report an issue: GitHub.