Tencent/APIJSON · error · IllegalArgumentException

{}:value 中 key 不合法!比较运算 [>, <, >=, <=] 不支持 [&, !, |] 中任何逻辑运算

Error message

{}:value 中 key 不合法!比较运算 [>, <, >=, <=] 不支持 [&, !, |] 中任何逻辑运算符 !

What it means

Thrown by gainCompareString when the column part of a comparison key fails StringUtil.isName(). Comparison keys (>, <, >=, <=) do not accept the '!' NOT suffix or '& |' logic characters, unlike the equality path; anything beyond a legal identifier is rejected.

Source

Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java:4058

		String rc = column.endsWith("[") || column.endsWith("{") ? column.substring(0, column.length() - 1) : column;
		if (StringUtil.isName(rc) == false) {
			throw new IllegalArgumentException(key + ":value 中key不合法!不支持 ! 以外的逻辑符 !");
		}

		String logic = value == null && rawSQL == null ? (not ? SQL.IS_NOT : SQL.IS) : (not ? " != " : " = ");
		return gainKey(column) + logic + (value instanceof Subquery ? gainSubqueryString((Subquery<T, M, L>) value)
				: (rawSQL != null ? rawSQL : gainValue(key, column, value)));
	}

	public String gainCompareString(String key, String column, Object value, String type, String rawSQL) throws Exception {
		if (value != null && JSON.isBoolOrNumOrStr(value) == false && value instanceof Subquery == false) {
			throw new IllegalArgumentException(key + ":value 中 value 不合法!比较运算 [>, <, >=, <=] 只支持 [Boolean, Number, String] 内的类型 !");
		}

		String rc = column.endsWith("[") || column.endsWith("{") ? column.substring(0, column.length() - 1) : column;
		if ( ! StringUtil.isName(rc)) {
			throw new IllegalArgumentException(key + ":value 中 key 不合法!比较运算 [>, <, >=, <=] 不支持 [&, !, |] 中任何逻辑运算符 !");
		}

		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("--")) {

View on GitHub (pinned to 5284052872)

Solutions

  1. Remove '!', '&', '|' from comparison keys: use "age>" not "age!>".
  2. To negate a range, invert the operator ("age<=" instead of "!(age>)") or use @combine with NOT semantics.
  3. Keep the base name a valid column identifier.

Example fix

// before
{"User": {"age!>": 18}}
// after
{"User": {"age<=": 18}}
Defensive patterns

Strategy: validation

Validate before calling

function isName(s) { return /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)*$/.test(s); }
for (const k of Object.keys(tableObj)) {
  const m = k.match(/^(.+?)(>=|<=|>|<)$/);
  if (m && !isName(m[1].replace(/[!\[\{]$/, ''))) throw new Error('bad compare key ' + k);
  if (m && /[&!|]/.test(m[1])) throw new Error('compare key must not contain & ! |');
}

Prevention

When it happens

Trigger: Keys like "age!>" 10, "price|>" 5, or comparison keys containing invalid identifier characters after the operator suffix is stripped.

Common situations: Assuming '!' works everywhere (it only works on plain equality keys); building comparison keys dynamically and appending extra symbols.

Related errors


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