{"record":{"id":"7312891fbe3bafc2","repo":"Tencent/APIJSON","slug":"methodname-rt-null","errorCode":null,"errorMessage":"远程函数 \" + methodName + \" 的实际返回值类型 \" + (rt == null ? null : rt.getName()) + \" 与 Function 表中的配置的 \" + fullReturnType + \" 不匹配！","messagePattern":"远程函数 \" \\+ methodName \\+ \" 的实际返回值类型 \" \\+ \\(rt == null \\? null : rt\\.getName\\(\\)\\) \\+ \" 与 Function 表中的配置的 \" \\+ fullReturnType \\+ \" 不匹配！","errorType":"exception","errorClass":"WrongMethodTypeException","httpStatus":null,"severity":"warning","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java","lineNumber":544,"sourceCode":"     * @param args\n     * @param returnType\n     * @param current\n     * @return\n     * @throws Exception\n     */\n\t@SuppressWarnings({\"unchecked\", \"rawtypes\"})\n    public static <T, M extends Map<String, Object>, L extends List<Object>> Object invokeScript(\n\t\t\t@NotNull AbstractFunctionParser<T, M, L> parser, @NotNull String methodName\n            , @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        }","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java#L526-L562","documentation":"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.","triggerScenarios":"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.","commonSituations":"JS function edited and the return statement dropped; returnType column left empty when the script actually returns data; null returned for edge-case inputs.","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."],"exampleFix":"// before (script row returnType='Number')\nfunction inc(x) { var v = x + 1; } // no return -> undefined\n\n// after\nfunction inc(x) { return x + 1; }","handlingStrategy":"validation","validationCode":"Object result = scriptExecutor.execute(...);\nString configured = (String) functionRow.get(\"returnType\");\nif ((result == null) != (configured == null || \"void\".equals(configured))) {\n    // script null-ness disagrees with configuration: fix script or row before shipping\n}","typeGuard":null,"tryCatchPattern":"try { invokeScript(...); } catch (WrongMethodTypeException e) { if (e.getMessage().contains(\"不匹配\")) { /* align script return with returnType column */ } throw e; }","preventionTips":["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."],"tags":["apijson","scripting","return-type","debug"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}