Tencent/APIJSON · error · IllegalArgumentException
字符 {} 不合法!远程函数不允许指定类名!且必须为 function(key0,key1,...) 这种单函数格式!\
Error message
字符 {} 不合法!远程函数不允许指定类名!且必须为 function(key0,key1,...) 这种单函数格式!\nfunction必须符合 Java 函数 命名,key 是用于在 request 内取值的键! What it means
Thrown by AbstractFunctionParser when a remote function call string contains a schema/class prefix (e.g. 'ClassName.method(...)' or 'db.schema.method(...)') while isSQLFunction is false. Remote (Java) functions may only be written in the single-function form function(key0,key1,...); the schema-qualified form schema.function(...) is reserved for SQL functions and stored procedures. The schema part is split off at the first '.' and its presence alone triggers this error for remote functions.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java:604
* @throws Exception
*/
public static FunctionBean parseFunction(@NotNull String function, @NotNull Map<String, Object> request, boolean isSQLFunction, boolean containRaw) throws Exception {
int start = function.indexOf("(");
int end = function.lastIndexOf(")");
String method = (start <= 0 || end != function.length() - 1) ? null : function.substring(0, start);
int dotInd = method == null ? -1 : method.indexOf(".");
String schema = dotInd < 0 ? null : method.substring(0, dotInd);
method = dotInd < 0 ? method : method.substring(dotInd + 1);
if (StringUtil.isName(method) == false) {
throw new IllegalArgumentException("字符 " + method + " 不合法!函数的名称 function 不能为空且必须符合方法命名规范!"
+ "总体必须为 function(key0,key1,...) 这种单函数格式!"
+ "\nfunction必须符合 " + (isSQLFunction ? "SQL 函数/SQL 存储过程" : "Java 函数") + " 命名,key 是用于在 request 内取值的键!");
}
if (isSQLFunction != true && schema != null) { // StringUtil.isNotEmpty(schema, false)) {
throw new IllegalArgumentException("字符 " + schema + " 不合法!远程函数不允许指定类名!"
+ "且必须为 function(key0,key1,...) 这种单函数格式!"
+ "\nfunction必须符合 " + (isSQLFunction ? "SQL 函数/SQL 存储过程" : "Java 函数") + " 命名,key 是用于在 request 内取值的键!");
}
if (schema != null) { // StringUtil.isName(schema) == false) {
schema = extractSchema(schema, null);
}
String[] keys = StringUtil.split(function.substring(start + 1, end));
int length = keys == null ? 0 : keys.length;
Class<?>[] types;
Object[] values;
if (isSQLFunction || IS_PARSE_ARG_VALUE) {
types = new Class<?>[length];
values = new Object[length];
//碰到null就挂了!!!Number还得各种转换不灵活!不如直接传request和对应的key到函数里,函数内实现时自己 getLongValue,getJSONObject ...View on GitHub (pinned to 5284052872)
Solutions
- Remove the class/schema prefix and keep only the bare Java method name: 'key()': 'trim(name)' instead of 'key()': 'StringUtil.trim(name)'.
- If you actually need a stored procedure / SQL function, use the SQL-function path (isSQLFunction true, e.g. '@column' or stored-procedure syntax) where schema.function(args) is allowed.
- If the method must live in a specific parser class, register the method on your FunctionParser implementation / via the remote function registry instead of naming the class in the request.
Example fix
// before
"User": { "name()": "com.example.MyParser.encode(id)" }
// after
"User": { "name()": "encode(id)" } // register encode() on your FunctionParser implementation Defensive patterns
Strategy: validation
Validate before calling
// Validate a remote function string before sending: bare method name + args
private static final Pattern REMOTE_FN = Pattern.compile("^[A-Za-z_$][A-Za-z0-9_$]*\\([^()]*\\)$");
boolean ok = REMOTE_FN.matcher(fn).matches(); // rejects 'Class.method(...)', 'schema.method(...)' Type guard
function isRemoteFunction(s: string): boolean {
return /^[A-Za-z_$][A-Za-z0-9_$]*\([^()]*\)$/.test(s) && !s.includes('.');
} Try / catch
try { response = parser.parse(request); } catch (IllegalArgumentException e) { if (e.getMessage().contains("不允许指定类名")) { /* strip class prefix, retry once */ } else throw e; } Prevention
- Keep remote function strings as bare method(key0,key1) with no dots.
- Reserve schema-qualified syntax for SQL functions / stored procedures only.
- Lint request builders for 'key():' values containing '.' before the parenthesis.
When it happens
Trigger: A request contains "@column": "myClass.trim(name)" or any 'key()': "some.Util.encode(arg)" style remote function value where the method segment contains a dot. Any APIJSON request whose function string for a remote (Java) function is 'package.Class.method(key)' or 'schema.method(key)' instead of 'method(key)'.
Common situations: Developers migrating from SQL-function syntax to remote functions, or copy-pasting stored-procedure syntax like 'db0.func(...)' into a remote function key. Also hitting it after a class-name refactor left a stale qualified name in front-end code.
Related errors
- {}/{}:value 中 value 必须为函数String!
- 字符 " + function + " 不合法!
- 子查询 {}/{}:{ range:value } 中 value 只能为 [ALL, ANY] 中的一个!
- 子查询 {}/{}:{ from:value } 中 value 对应的主表对象 {}:{} 不存在!
- {}/{}:value 中 value 必须为 依赖路径String 或 SQL子查询JSONObject !
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/19bf4301a05de7af.
Report an issue: GitHub.