Tencent/APIJSON · error · IllegalArgumentException

{}:{ @combine:'{}' } 中字符 '{}' 不合法!左边缺少 & | 逻辑连接符!逻辑连接符 & | 左

Error message

{}:{ @combine:'{}' } 中字符 '{}' 不合法!左边缺少 & | 逻辑连接符!逻辑连接符 & | 左右必须各一个相邻空格!空格不能多也不能少!不允许首尾有空格,也不允许连续空格!左括号 ( 的右边 和 右括号 ) 的左边 都不允许有相邻空格!

What it means

When '!' appears in operator position (after a space or '('), it must itself follow a logic operator: the guard i > 0 && lastLogic <= 0 && last != '(' throws when no & or | has been seen since the last term. I.e., '!' cannot be the first connector in a group or expression — it is a modifier on a term, not a standalone joiner, so "!a & b" at the start is fine (last=='(' or start) but "a !b" (nothing between a and !b) is not.

Source

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

					}
				}
				else if (c == '!') {
					last = i <= 0 ? 0 : s.charAt(i - 1);  // & | 后面跳过了空格

					char next = i >= n - 1 ? 0 : s.charAt(i + 1);
					if (last == ' ' || last == '(') {
						if (next == ' ') {
							throw new IllegalArgumentException(errPrefix + " 中字符 '" + s.substring(0, i + 1)
							+ "' 不合法!非逻辑符 '!' 右边多了一个空格 ' ' !非逻辑符 '!' " +
									"右边不允许任何相邻空格 ' ',也不允许 ')' '&' '|' 中任何一个!");
						}
						if (next == ')' || next == '&' || next == '!') {
							throw new IllegalArgumentException(errPrefix + " 中字符 '" + s.substring(0, i + 1)
							+ "' 不合法!非逻辑符 '!' 右边多了一个字符 '"
									+ next + "' !非逻辑符 '!' 右边不允许任何相邻空格 ' ',也不允许 ')' '&' '|' 中任何一个!");
						}
						if (i > 0 && lastLogic <= 0 && last != '(') {
							throw new IllegalArgumentException(errPrefix + " 中字符 '" + s.substring(i)
							+ "' 不合法!左边缺少 & | 逻辑连接符!逻辑连接符 & | 左右必须各一个相邻空格!空格不能多也不能少!"
							+ "不允许首尾有空格,也不允许连续空格!左括号 ( 的右边 和 右括号 ) 的左边 都不允许有相邻空格!");
						}
					}

					if (next == '(') {
						result += SQL.NOT;
						lastLogic = c;
					}
					else if (last <= 0 || last == ' ' || last == '(') {
						isNot = true;
						//					lastLogic = c;
					}
					else {
						key += c;
					}
				}
				else if (c == '(') {

View on GitHub (pinned to 5284052872)

Solutions

  1. Always precede a '!term' with '& ' or '| ' unless it is the very first term or right after '(': "id & !name".
  2. Treat ! as part of the operand, and keep the normal operator between operands.
  3. Validate with the strict grammar regex before sending (see validation code).

Example fix

// before
{"@combine":"id !deleted"}
// after
{"@combine":"id & !deleted"}
Defensive patterns

Strategy: validation

Validate before calling

// every '!term' (except at start / right after '(') must be preceded by '& ' or '| '
String norm = combine.replaceAll("\\([\\w!&|() ]*\\)", "K");
if (norm.matches(".*[\\w)]\\s*!.*") || norm.matches(".*[\\w)]!.*"))
    throw new IllegalArgumentException("'!' term missing & or | before it");

Type guard

function notTermsPreceded(s: string): boolean {
  const norm = s.replace(/\([\w!&|() ]*\)/g, 'K');
  return !/[\wK)]\s*!/.test(norm); // no ! directly after a term or group without an operator
}

Prevention

When it happens

Trigger: @combine:"id !name" (missing & before the NOT term), or "(a !b)" inside a group. lastLogic is only set >0 when & | ! (before '(') was consumed, so a bare "key !key" sequence leaves it 0 and throws at line 3595 with the remainder s.substring(i).

Common situations: Assuming '!key' alone negates-and-joins like 'and not'; deleting an '&' between a term and a '!term' during edits; building expressions by concatenation and dropping the operator before a NOT'd optional filter.

Related errors


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