Tencent/APIJSON · warning · WrongMethodTypeException
远程函数 " + methodName + " 的实际返回值类型 " + (rt == null ? null : rt
Error message
远程函数 " + methodName + " 的实际返回值类型 " + (rt == null ? null : rt.getName()) + " 与 Function 表中的配置的 " + fullReturnType + " 不匹配!
What it means
Debug-mode check in invokeScript: after a script (non-Java) remote function executes, if the result's null-ness disagrees with the configured returnType in the Function table (result null but returnType set, or result non-null but returnType null/void), APIJSON throws WrongMethodTypeException. It catches scripts that returned undefined/null when they promised a value, or vice versa.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java:544
* @param args
* @param returnType
* @param current
* @return
* @throws Exception
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public static <T, M extends Map<String, Object>, L extends List<Object>> Object invokeScript(
@NotNull AbstractFunctionParser<T, M, L> parser, @NotNull String methodName
, @NotNull Class<?>[] parameterTypes, @NotNull Object[] args, String returnType
, Map<String, Object> current, ScriptExecutor scriptExecutor) throws Exception {
Object result = scriptExecutor.execute(parser, current, methodName, args);
if (Log.DEBUG && result != null) {
Class<?> rt = result.getClass(); // 作为远程函数的 js 类型应该只有 JSON 的几种类型
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 + " 不匹配!");
}
}View on GitHub (pinned to 5284052872)
Solutions
- Fix the script so it always returns a value of the configured type (add/repair the return statement).
- Or align the Function row's returnType with what the script actually returns (set it, or clear it if the result is legitimately null).
- Handle null-producing inputs inside the script with defaults.
Example fix
// before (script row returnType='Number')
function inc(x) { var v = x + 1; } // no return -> undefined
// after
function inc(x) { return x + 1; } Defensive patterns
Strategy: validation
Validate before calling
Object result = scriptExecutor.execute(...);
String configured = (String) functionRow.get("returnType");
if ((result == null) != (configured == null || "void".equals(configured))) {
// script null-ness disagrees with configuration: fix script or row before shipping
} Try / catch
try { invokeScript(...); } catch (WrongMethodTypeException e) { if (e.getMessage().contains("不匹配")) { /* align script return with returnType column */ } throw e; } Prevention
- Unit-test script functions over representative inputs (including nulls) to confirm they always return the configured type.
- Set returnType only when the script guarantees a value; clear it for intentionally void functions.
- Exercise scripts under Log.DEBUG=true in CI.
When it happens
Trigger: Function row language='javascript' with returnType='Number', but the JS function returns undefined (e.g. missing return statement) — or a void-configured function returns a value — while Log.DEBUG is true.
Common situations: JS function edited and the return statement dropped; returnType column left empty when the script actually returns data; null returned for edge-case inputs.
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/7312891fbe3bafc2.
Report an issue: GitHub.