{"record":{"id":"73d35d41a1835213","repo":"Tencent/APIJSON","slug":"methodname-function-re","errorCode":null,"errorMessage":"远程函数 \" + methodName + \" 在 Function 表中的配置的类型 \" + returnType + \" 对应的 \" + fullReturnType + \" 错误！在 Java 中 Class.forName 找不到这个类型！","messagePattern":"远程函数 \" \\+ methodName \\+ \" 在 Function 表中的配置的类型 \" \\+ returnType \\+ \" 对应的 \" \\+ fullReturnType \\+ \" 错误！在 Java 中 Class\\.forName 找不到这个类型！","errorType":"exception","errorClass":"WrongMethodTypeException","httpStatus":null,"severity":"warning","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java","lineNumber":553,"sourceCode":"            , @NotNull Class<?>[] parameterTypes, @NotNull Object[] args, String returnType\n\t\t\t, Map<String, Object> current, ScriptExecutor scriptExecutor) throws Exception {\n    \tObject result = scriptExecutor.execute(parser, current, methodName, args);\n        if (Log.DEBUG && result != null) {\n            Class<?> rt = result.getClass(); // 作为远程函数的 js 类型应该只有 JSON 的几种类型\n            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","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java#L535-L571","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Correct the returnType column: use simple names like 'String', 'Number', 'Boolean', 'JSONObject', or a fully-qualified class name that exists on the classpath.","If a custom type is needed, provide the fully-qualified name of a class actually loadable by the backend.","Test Function-row returnType values in a dev environment with Log.DEBUG=true before rollout."],"exampleFix":"-- before\nUPDATE sys.Function SET returnType='Strng' ... -- typo\n\n-- after\nUPDATE sys.Function SET returnType='String' WHERE name='enc';","handlingStrategy":"validation","validationCode":"String returnType = (String) functionRow.get(\"returnType\");\nif (returnType != null && StringUtil.isSmallName(returnType)\n        && !returnType.startsWith(\"JSON\")) {\n    try { Class.forName(\"java.lang.\" + returnType); }\n    catch (ClassNotFoundException e) { /* invalid simple name in Function row */ }\n}","typeGuard":"public static boolean returnTypeResolvable(String returnType) {\n    if (returnType == null) return true;\n    String full = StringUtil.isSmallName(returnType) ? \"java.lang.\" + returnType : returnType;\n    if (returnType.startsWith(\"JSON\")) full = \"com.alibaba.fastjson.\" + returnType;\n    try { Class.forName(full); return true; } catch (ClassNotFoundException e) { return false; }\n}","tryCatchPattern":"try { invokeScript(...); } catch (WrongMethodTypeException e) { if (e.getMessage().contains(\"Class.forName\")) { /* fix returnType spelling/full name in Function row */ } throw e; }","preventionTips":["Whitelist returnType values in Function-table editing tooling (String, Number, Boolean, JSONObject, JSONArray, or FQCNs).","Validate Function rows with a migration-time lint script.","Remember simple names resolve under java.lang or com.alibaba.fastjson only."],"tags":["apijson","scripting","return-type","classloading","configuration"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}