Tencent/APIJSON · error · IllegalArgumentException

字符 " + function + " 对应的远程函数传参类型错误!\n请检查 key:value 中value的类型是

Error message

字符 " + function + " 对应的远程函数传参类型错误!\n请检查 key:value 中value的类型是否满足已定义的函数 " + getFunction(fb.getMethod(), fb.getKeys()) + " 的要求!" + (Log.DEBUG ? e.getMessage() : "")

What it means

The reflective call reached a real method but java.lang.reflect.InvocationTargetException fired and the underlying target exception had no message (common for NullPointerException/ClassCastException inside the function or for mismatched argument types). APIJSON cannot rethrow an informative exception, so it reports a parameter-type error and reminds you that each key's value type must satisfy the method signature.

Source

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

		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;
		}

	}

	/**反射调用
     * @param parser
     * @param methodName
     * @param parameterTypes
     * @param args
     * @return {@link #invoke(AbstractFunctionParser, String, Class[], Object[])}
     * @throws Exception
     */
	@SuppressWarnings({"unchecked", "rawtypes"})
	public static <T, M extends Map<String, Object>, L extends List<Object>> Object invoke(

View on GitHub (pinned to 5284052872)

Solutions

  1. Check each key:value pair in the function call against the Java method's parameter types and fix the request values.
  2. Ensure referenced keys exist in the current object so arguments are not null.
  3. Widen the Java method signature (e.g. accept Object or Number and convert internally) for tolerant parsing.
  4. Turn on Log.DEBUG so e.getMessage() from the target exception is appended to this error for diagnosis.

Example fix

// before: long id parameter, request sends string
{"@column":"enc(id)"} // id = "123" -> fails

// after
public Object enc(Object id) { long v = Long.parseLong(String.valueOf(id)); ... }
Defensive patterns

Strategy: validation

Validate before calling

for (Object arg : resolvedArgs) {
    if (arg == null) { /* referenced key missing in request: fail fast with key name */ }
}
// and compare each arg's class against the target method's parameter types before invoke

Type guard

public static boolean argsMatch(Method m, Object[] args) {
    Class<?>[] p = m.getParameterTypes();
    if (p.length != args.length) return false;
    for (int i = 0; i < args.length; i++) { if (args[i] != null && !p[i].isInstance(args[i]) && !isWidening(args[i], p[i])) return false; }
    return true;
}

Try / catch

try { parser.invoke(fn, current); } catch (IllegalArgumentException e) { if (e.getMessage().contains("传参类型错误")) { /* check key:value types vs method signature; enable Log.DEBUG for detail */ } throw e; }

Prevention

When it happens

Trigger: Function arguments resolved from the request have runtime types that fail inside the method (e.g. String passed where Long expected causing ClassCastException, or a null key causing NPE) and the target exception message is empty.

Common situations: Request omits a key so the method receives null; JSON numbers deserialize as Integer while the method expects Long; string vs number confusion for id fields.

Related errors


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