Tencent/APIJSON · error · IllegalArgumentException

{}:{ @combine:'{}' } 中字符 '{}' 不合法!非逻辑符 '!' 右边多了一个空格 ' ' !非逻辑

Error message

{}:{ @combine:'{}' } 中字符 '{}' 不合法!非逻辑符 '!' 右边多了一个空格 ' ' !非逻辑符 '!' 右边不允许任何相邻空格 ' ',也不允许 ')' '&' '|' 中任何一个!

What it means

'!' is the NOT prefix and is only an operator when preceded by a space or '(' (last == ' ' || last == '('). In operator position, the char after '!' must not be a space: "! key" is invalid because ! binds directly to the following term/group. This error fires when next == ' ' — i.e. "! " with whitespace between ! and its operand.

Source

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

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

						result += SQL.OR;
						lastLogic = c;
						i ++;
					}
					else {
						key += c;
					}
				}
				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;

View on GitHub (pinned to 5284052872)

Solutions

  1. Attach '!' directly to its operand with no space: "id & !name" or "!(a | b)".
  2. Remember the asymmetry: & and | take single spaces both sides; ! takes none on the right.
  3. Pre-validate with the grammar regex that rejects '! ' (see validation code).

Example fix

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

Strategy: validation

Validate before calling

if (combine.contains("! ") || combine.contains("!&") || combine.contains("!|"))
    throw new IllegalArgumentException("'!' must attach directly to its operand, no space/connector after it");

Type guard

function validNotUsage(s: string): boolean {
  return !/!\s/.test(s) && !/[!&|]\s*!/.test(s.replace(/[&|]\s!/g, '')) || true; // simplest: forbid '! '
  // practical guard:
  // return !s.includes('! ');
}

Prevention

When it happens

Trigger: @combine:"id & ! name" (space after '!'), or "( ! a)". The parser throws with the prefix up to and including '!' shown, at line 3585. '!key' and '!(...)' are the only valid forms.

Common situations: Treating '!' like '&'/'|' and spacing it symmetrically ("a & ! b"); formatting tools auto-spacing operators; developers reading the 'exactly one space around logic operators' rule and applying it to ! too.

Related errors


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