Tencent/APIJSON · error · IllegalArgumentException
字符 " + method + " 不合法!函数的名称 function 不能为空且必须符合方法命名规范!总体必须为 f
Error message
字符 " + method + " 不合法!函数的名称 function 不能为空且必须符合方法命名规范!总体必须为 function(key0,key1,...) 这种单函数格式!\nfunction必须符合 " + (isSQLFunction ? "SQL 函数/SQL 存储过程" : "Java 函数") + " 命名,key 是用于在 request 内取值的键!
What it means
parseFunction validates the grammar of a function expression: it must be a single call of the form function(key0,key1,...) where the method name (text before '(' and after an optional schema prefix) passes StringUtil.isName — Java-style identifier rules. If the parentheses are misplaced, the name is empty, or it contains illegal characters, IllegalArgumentException is thrown, with the message adapting to whether a SQL function or Java remote function was expected.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java:599
* @param function
* @param request
* @param isSQLFunction
* @param containRaw
* @return
* @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;
View on GitHub (pinned to 5284052872)
Solutions
- Rewrite the expression as name(arg0,arg1,...) with a valid identifier name and no spaces.
- Validate user-built expressions with StringUtil.isName on the name part and a parentheses check before sending.
- For plain column references, drop the function syntax entirely (just "id").
- For schema-qualified SQL functions use schema.func(key) and remember remote (Java) functions forbid schema prefixes.
Example fix
// before
{"User":{"@column":"mask Phone(phone)"}} // space in name
// after
{"User":{"@column":"maskPhone(phone)"}} Defensive patterns
Strategy: validation
Validate before calling
int start = function.indexOf('(');
int end = function.lastIndexOf(')');
String name = (start > 0 && end == function.length() - 1) ? function.substring(0, start) : null;
int dot = name == null ? -1 : name.indexOf('.');
if (dot >= 0) name = name.substring(dot + 1);
boolean valid = name != null && StringUtil.isName(name) && !function.contains(" "); Type guard
public static boolean isValidFunctionExpr(String function) {
if (StringUtil.isEmpty(function, true)) return false;
int s = function.indexOf('('), e = function.lastIndexOf(')');
if (s <= 0 || e != function.length() - 1) return false;
String name = function.substring(0, s);
int d = name.indexOf('.');
if (d >= 0) name = name.substring(d + 1);
return StringUtil.isName(name) && !function.matches(".*\\s.*");
} Try / catch
try { parser.invoke(function, current); } catch (IllegalArgumentException e) { if (e.getMessage().contains("不合法")) { /* reject/repair expression before retry */ } throw e; } Prevention
- Build function expressions from validated constants, never raw user input.
- Reject any expression containing whitespace before sending.
- Require the exact single-function form name(key0,key1,...); no nested or multiple calls.
When it happens
Trigger: Passing "sum(id" (missing ')'), "(a,b)" (empty name), "my-func(a)" or "my func(a)" (illegal characters), "function() extra", or a plain string "abc" without parentheses — note start<=0 also rejects bare names, since the '(' at index >0 is required and ')' must be last.
Common situations: Client builds function strings via concatenation and produces spaces or truncation; user-supplied input interpolated directly into @column/@having; switching a plain column name to a function call and forgetting the parentheses; schema prefix issues for SQL functions.
Related errors
- Cannot convert value of type " + value.getClass().getName()
- 字符 " + function + " 不合法!
- 字符 {} 不合法!远程函数不允许指定类名!且必须为 function(key0,key1,...) 这种单函数格式!\
- {}: { @key(): value } 对应存储过程 value 中字符 {} 不合法!`schema` 当有 `
- {}: { @key(): value } 对应存储过程 value 中字符 `{} 不合法!`schema` 当有 `
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/9fb9880b228196f5.
Report an issue: GitHub.