{"record":{"id":"6a0de11a8328ddc3","repo":"Tencent/APIJSON","slug":"methodname-rt-func","errorCode":null,"errorMessage":"远程函数 \" + methodName + \" 的实际返回值类型 \" + rt + \" 与 Function 表中的配置的 \" + returnType + \" 不匹配！","messagePattern":"远程函数 \" \\+ methodName \\+ \" 的实际返回值类型 \" \\+ rt \\+ \" 与 Function 表中的配置的 \" \\+ returnType \\+ \" 不匹配！","errorType":"exception","errorClass":"WrongMethodTypeException","httpStatus":null,"severity":"warning","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java","lineNumber":515,"sourceCode":"        if (scriptExecutor != null) {\n            return invokeScript(parser, methodName, parameterTypes, args, returnType, current, scriptExecutor);\n        }\n\n\t\tClass<? extends AbstractFunctionParser> cls = parser.getClass();\n        Method m = cls.getMethod(methodName, parameterTypes); // 不用判空，拿不到就会抛异常\n\n        if (Log.DEBUG) {\n            String rt = Log.DEBUG && m.getReturnType() != null ? m.getReturnType().getSimpleName() : null;\n\n            if (\"void\".equals(rt)) {\n                rt = null;\n            }\n            if (\"void\".equals(returnType)) {\n                returnType = null;\n            }\n\n            if (rt != returnType && (rt == null || rt.equals(returnType) == false)) {\n                throw new WrongMethodTypeException(\"远程函数 \" + methodName + \" 的实际返回值类型 \" + rt + \" 与 Function 表中的配置的 \" + returnType + \" 不匹配！\");\n            }\n        }\n\n        return m.invoke(parser, args);\n\t}\n\n    /**Java 调用 JavaScript 函数\n     * @param parser\n     * @param methodName\n     * @param parameterTypes\n     * @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(","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java#L497-L533","documentation":"In debug mode (Log.DEBUG == true), after reflectively invoking a Java remote function, APIJSON validates that the method's declared return type matches the returnType configured in the Function table row, throwing WrongMethodTypeException on mismatch. It only runs when debugging is enabled, acting as a development-time consistency check between code and table configuration.","triggerScenarios":"Function table row says returnType='String' but the Java method is declared to return Object/Long; running with Log.DEBUG=true in a dev environment exposes the mismatch that production silently ignores.","commonSituations":"Method signature changed during refactoring without updating the Function row; demo rows have stale returnType values; switching debug on in a CI environment suddenly surfaces latent mismatches.","solutions":["Update the Function table's returnType column to exactly match the Java method's return type (simple name, e.g. 'String').","Or change the Java method's return type to the configured one.","Treat this as a signal to reconcile the table — the mismatch may cause wrong response serialization in production.","If 'void' is involved, note both sides normalize void to null."],"exampleFix":"-- before: method returns Long, table says returnType='String'\nUPDATE sys.Function SET returnType='Long' WHERE name='enc';\n\n-- or change Java: public String enc(...) { return String.valueOf(id); }","handlingStrategy":"validation","validationCode":"if (Log.DEBUG) {\n    Method m = parser.getClass().getMethod(fb.getMethod(), fb.getTypes());\n    String declared = m.getReturnType().getSimpleName();\n    String configured = (String) functionRow.get(\"returnType\");\n    boolean mismatch = !\"void\".equals(declared) && !\"void\".equals(configured)\n        && !declared.equals(configured);\n}","typeGuard":null,"tryCatchPattern":"try { m.invoke(parser, args); } catch (WrongMethodTypeException e) { if (e.getMessage().contains(\"Function 表\")) { /* sync returnType column with method return type */ } throw e; }","preventionTips":["Run dev/CI with Log.DEBUG=true to catch table/code drift before production.","When refactoring a function's return type, update the Function row in the same commit.","Automate a check comparing Function rows to parser method signatures."],"tags":["apijson","remote-function","return-type","debug","configuration"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}