Tencent/APIJSON · warning · WrongMethodTypeException

远程函数 " + methodName + " 在 Function 表中的配置的类型 " + returnType +

Error message

远程函数 " + methodName + " 在 Function 表中的配置的类型 " + returnType + " 对应的 " + fullReturnType + " 错误!在 Java 中 Class.forName 找不到这个类型!

What it means

Debug-mode check in invokeScript: the configured returnType is expanded to a fully-qualified class name (small names get a 'java.lang.' or 'com.alibaba.fastjson.' prefix depending on content) and loaded with Class.forName; if the class does not exist, WrongMethodTypeException is thrown because the Function table's return type cannot be mapped to any Java type.

Source

Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java:553

            , @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 + " 不匹配!");
            }
        }

        Log.d(TAG, "invokeScript " + methodName + "(..) >>  result = " + result);
        return result;
    }


    /**解析函数
     * @param function
     * @param request

View on GitHub (pinned to 5284052872)

Solutions

  1. Correct the returnType column: use simple names like 'String', 'Number', 'Boolean', 'JSONObject', or a fully-qualified class name that exists on the classpath.
  2. If a custom type is needed, provide the fully-qualified name of a class actually loadable by the backend.
  3. Test Function-row returnType values in a dev environment with Log.DEBUG=true before rollout.

Example fix

-- before
UPDATE sys.Function SET returnType='Strng' ... -- typo

-- after
UPDATE sys.Function SET returnType='String' WHERE name='enc';
Defensive patterns

Strategy: validation

Validate before calling

String returnType = (String) functionRow.get("returnType");
if (returnType != null && StringUtil.isSmallName(returnType)
        && !returnType.startsWith("JSON")) {
    try { Class.forName("java.lang." + returnType); }
    catch (ClassNotFoundException e) { /* invalid simple name in Function row */ }
}

Type guard

public static boolean returnTypeResolvable(String returnType) {
    if (returnType == null) return true;
    String full = StringUtil.isSmallName(returnType) ? "java.lang." + returnType : returnType;
    if (returnType.startsWith("JSON")) full = "com.alibaba.fastjson." + returnType;
    try { Class.forName(full); return true; } catch (ClassNotFoundException e) { return false; }
}

Try / catch

try { invokeScript(...); } catch (WrongMethodTypeException e) { if (e.getMessage().contains("Class.forName")) { /* fix returnType spelling/full name in Function row */ } throw e; }

Prevention

When it happens

Trigger: Function row returnType contains a typo ('Strng') or an unknown simple name that expands to a nonexistent class (e.g. 'Foo' -> java.lang.Foo), while Log.DEBUG is true and the script returned a value.

Common situations: Hand-edited Function rows with typos; using non-simple, non-fully-qualified custom type names that don't live under java.lang/fastjson; copying rows between systems with different available classes.

Related errors


AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14). Data as JSON: /api/errors/73d35d41a1835213. Report an issue: GitHub.