Tencent/APIJSON · error · IllegalArgumentException
参数 {} 不合法!key 中不允许有单引号 ' !
Error message
参数 {} 不合法!key 中不允许有单引号 ' ! What it means
Thrown by gainKey only when isTest() is true: the key contains a single quote character. In test mode the library passes keys through gainSQLValue directly (no prepared-statement placeholder path), so a quote could break out of the string and is rejected as an SQL-injection guard.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java:4077
}
return gainKey(column) + " " + type + " " + (value instanceof Subquery ? gainSubqueryString((Subquery<T, M, L>) value)
: (rawSQL != null ? rawSQL : gainValue(key, column, value)));
}
public String gainKey(@NotNull String key) {
String lenFun = "";
if (key.endsWith("[")) {
lenFun = isSQLServer() || isKingBaseSQLServer() ? "datalength" : "length";
key = key.substring(0, key.length() - 1);
}
else if (key.endsWith("{")) {
lenFun = "json_length";
key = key.substring(0, key.length() - 1);
}
else if (isTest()) {
if (key.contains("'")) { // || key.contains("#") || key.contains("--")) {
throw new IllegalArgumentException("参数 " + key + " 不合法!key 中不允许有单引号 ' !");
}
return gainSQLValue(key).toString();
}
Map<String, String> keyMap = getKeyMap();
String expression = keyMap == null ? null : keyMap.get(key);
if (expression == null) {
expression = COLUMN_KEY_MAP == null ? null : COLUMN_KEY_MAP.get(key);
}
String sqlKey;
if (expression == null) {
sqlKey = gainSQLKey(key);
}
else {
// (name,tag) left(date,4) 等
List<String> raw = getRaw();
sqlKey = parseSQLExpression(KEY_KEY, expression, raw != null && raw.contains(KEY_KEY), false);View on GitHub (pinned to 5284052872)
Solutions
- Remove single quotes from keys/values; escape or drop them client-side.
- If the quote is legitimate data, pass it as a prepared value (condition value), not as part of the key.
- Verify isTest() is not accidentally enabled in production or CI configuration.
Example fix
// before
{"User": {"name'": "az"}}
// after
{"User": {"name": "az"}} Defensive patterns
Strategy: validation
Validate before calling
if (isTestMode && key.includes("'")) throw new Error("key must not contain a single quote in test mode"); Prevention
- Sanitize all user-supplied key fragments: strip quotes before building requests.
- Keep quotes in values (prepared), never in keys.
- Audit where isTest() gets enabled; keep it off in shared environments.
When it happens
Trigger: Running with the test/debug flag enabled (isTest()) and sending a condition key or @column expression containing ' — e.g. dynamically built keys like "name'" or raw column fragments with quotes.
Common situations: Unit/integration tests that enable test mode and then feed user-controlled key strings; leftover isTest configuration in a deployment pipeline.
Related errors
- {}: { @key(): value } 对应存储过程 value 中字符 {} 不合法!schema.functio
- @group:value 中 value里面用 , 分割的每一项都必须是1个单词!并且不要有空格!
- 字符串 ${expression} 不合法!预编译模式下 @having:"column?value;function(
- 预编译模式下 @order:value 中 {item} 不合法! value 里面用 , 分割的每一项必须是 随机函数
- 字符 {ck} 不合法!预编译模式下 @column:"column0,column1:alias;function0(
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/71d33eb72b552a28.
Report an issue: GitHub.