Tencent/APIJSON · error · IllegalArgumentException

字符 " + function + " 对应的远程函数 " + getFunction(fb.getMethod(),

Error message

字符 " + function + " 对应的远程函数 " + getFunction(fb.getMethod(), fb.getKeys()) + " 不在后端 " + parser.getClass().getName() + " 内,也不在父类中!如果需要则先新增对应方法!\n请检查函数名和参数数量是否与已定义的函数一致!\n且必须为 function(key0,key1,...) 这种单函数格式!\nfunction 必须符合 Java 函数命名,key 是用于在 curObj 内取值的键!\n调用时不要有空格!" + (Log.DEBUG ? e.getMessage() : "")

What it means

All Function-table gates passed, so the parser reflectively invokes the method on the parser object (your APIJSONFunctionParser subclass), but java.lang.reflect reports NoSuchMethodException: no method with that name and parameter count/types exists on the parser class or its superclasses. The message embeds the expected signature and reminder that arguments must be key references in function(key0,key1,...) form.

Source

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

		if (parser.getVersion() < version) {
			throw new UnsupportedOperationException("不允许 version = " + parser.getVersion() + " 的请求调用远程函数 " + fb.getMethod() + " ! 必须满足 version >= " + version + " !");
		}
		String tag = (String) row.get("tag");  // TODO 改为 tags,类似 methods 支持多个 tag。或者干脆不要?因为目前非开放请求全都只能后端指定
		if (tag != null && tag.equals(parser.getTag()) == false) {
			throw new UnsupportedOperationException("不允许 tag = " + parser.getTag() + " 的请求调用远程函数 " + fb.getMethod() + " ! 必须满足 tag = " + tag + " !");
		}
		String[] methods = StringUtil.split((String) row.get("methods"));
		List<String> ml = methods == null || methods.length <= 0 ? null : Arrays.asList(methods);
		if (ml != null && ml.contains(parser.getMethod().toString()) == false) {
			throw new UnsupportedOperationException("不允许 method = " + parser.getMethod() + " 的请求调用远程函数 " + fb.getMethod() + " ! 必须满足 method 在 " + Arrays.toString(methods) + "内 !");
		}

		try {
            return invoke(parser, fb.getMethod(), fb.getTypes(), fb.getValues(), (String) row.get("returnType"), current, SCRIPT_EXECUTOR_MAP.get(lang));
		}
        catch (Exception e) {
			if (e instanceof NoSuchMethodException) {
				throw new IllegalArgumentException("字符 " + function + " 对应的远程函数 " + getFunction(fb.getMethod(), fb.getKeys())
                        + " 不在后端 " + parser.getClass().getName() + " 内,也不在父类中!如果需要则先新增对应方法!"
						+ "\n请检查函数名和参数数量是否与已定义的函数一致!"
						+ "\n且必须为 function(key0,key1,...) 这种单函数格式!"
						+ "\nfunction 必须符合 Java 函数命名,key 是用于在 curObj 内取值的键!"
						+ "\n调用时不要有空格!" + (Log.DEBUG ? e.getMessage() : ""));
			}
			if (e instanceof InvocationTargetException) {
				Throwable te = ((InvocationTargetException) e).getTargetException();
				if (StringUtil.isEmpty(te.getMessage(), true) == false) { //到处把函数声明throws Exception改成throws Throwable挺麻烦
					throw te instanceof Exception ? (Exception) te : new Exception(te.getMessage());
				}
				throw new IllegalArgumentException("字符 " + function + " 对应的远程函数传参类型错误!"
						+ "\n请检查 key:value 中value的类型是否满足已定义的函数 " + getFunction(fb.getMethod(), fb.getKeys()) + " 的要求!"
						+ (Log.DEBUG ? e.getMessage() : ""));
			}
			throw e;
		}

View on GitHub (pinned to 5284052872)

Solutions

  1. Implement (or fix) the public method in your APIJSONFunctionParser subclass with exactly the name and parameter types the calls pass.
  2. Match parameter count: function(key0,key1) must map to a two-argument method.
  3. If the method exists in another class, move it into the parser class hierarchy or add a delegating method.
  4. Enable Log.DEBUG temporarily to append the underlying NoSuchMethodException detail to the message.

Example fix

// before: request uses maskPhone(phone) but parser lacks it

// after
class APIJSONFunctionParser extends AbstractFunctionParser<Long> {
    public Object maskPhone(String phone) { return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"); }
}
Defensive patterns

Strategy: try-catch

Validate before calling

Method m = null;
for (Method c : parser.getClass().getMethods()) {
    if (c.getName().equals(fb.getMethod()) && c.getParameterCount() == fb.getKeys().length) { m = c; break; }
}
if (m == null) { /* method missing: implement it before deploying the client change */ }

Try / catch

try { return parser.invoke(fn, current); } catch (IllegalArgumentException e) { if (e.getMessage().contains("不在后端")) { throw new UnsupportedOperationException("Remote function not implemented backend-side: " + fn, e); } throw e; }

Prevention

When it happens

Trigger: Function table registers 'maskPhone' but the backend APIJSONFunctionParser defines maskPhone(Long) while the request calls maskPhone(phone) where phone resolves to a String; or the method simply is not implemented yet; or parameter count differs.

Common situations: Frontend adds a function call before the backend method exists; refactor renamed a Java method without updating the Function table; argument-count mismatch between the call expression and the Java signature.

Related errors


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