Tencent/APIJSON · error · IllegalArgumentException

{errPrefix} 中字符 '{s}' 不合法!空格 ' ' 左边缺少条件 key !逻辑连接符 & | 左右必须各

Error message

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

What it means

During character-by-character parsing of @combine, when the scanner hits a space or ')' (or end of input) and no condition key has been accumulated (key empty) while the previous char was not ')', the expression is malformed: a space or closing parenthesis appeared with no key to its left. This covers cases like "a & & b", "a &", "( )", "a & b" (double space collapses to an empty key).

Source

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

			int depth = 0;
			int allCount = 0;

			int i = 0;

			char lastLogic = 0;
			char last = 0;
			boolean first = true;
			boolean isNot = false;

			String key = "";
			while (i <= n) {  // "date> | (contactIdList<> & (name*~ | tag&$))"
				boolean isOver = i >= n;
				char c = isOver ? 0 : s.charAt(i);
				boolean isBlankOrRightParenthesis = c == ' ' || c == ')';
				if (isOver || isBlankOrRightParenthesis) {
					boolean isEmpty = StringUtil.isEmpty(key, true);
					if (isEmpty && last != ')') {
						throw new IllegalArgumentException(errPrefix + " 中字符 '" + (isOver ? s : s.substring(i))
								+ "' 不合法!" + (c == ' ' ? "空格 ' ' " : "右括号 ')'") + " 左边缺少条件 key !逻辑连接符 & | 左右必须各一个相邻空格!"
								+ "空格不能多也不能少!不允许首尾有空格,也不允许连续空格!左括号 ( 的右边 和 右括号 ) 的左边 都不允许有相邻空格!");
					}

					if (isEmpty == false) {
						if (first == false && lastLogic <= 0) {
							throw new IllegalArgumentException(errPrefix + " 中字符 "
									+ "'" + s.substring(i - key.length() - (isOver ? 1 : 0))
									+ "' 不合法!左边缺少 & | 其中一个逻辑连接符!");
						}

						allCount ++;
						if (allCount > maxCombineCount && maxCombineCount > 0) {
							throw new IllegalArgumentException(errPrefix + " 中字符 '" + s + "' 不合法!"
									+ "其中 key 数量 " + allCount + " 已超过最大值,必须在条件键值对数量 0-" + maxCombineCount + " 内!");
						}

						String column = key;

View on GitHub (pinned to 5284052872)

Solutions

  1. Rewrite so every & and | is surrounded by exactly one space and always sits between two keys or groups: "id & (name | tag)".
  2. Never chain two operators; use parentheses for grouping instead.
  3. Build combine strings from key lists with a join helper (see validation code) instead of string concatenation.
  4. Validate with a strict grammar regex before sending (see validation code).

Example fix

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

Strategy: validation

Validate before calling

static final Pattern COMBINE = Pattern.compile("^[!\\w]+(\\s[&|]\\s[!\\w]+|\\s[&|]\\s\\([\\w&|!() ]+\\))*$"); // then also check no "  ", no "()"
if (!COMBINE.matcher(combine).matches() || combine.contains("  ") || combine.contains("()")) throw new IllegalArgumentException("bad @combine");

Type guard

function isWellFormedCombine(s: string): boolean {
  return !/^\s|\s$/.test(s) && !/\s{2}/.test(s) && !/[&(]\s|\s[)!]/.test(s.replace(/ & | \| /g, '')) === false;
}

Prevention

When it happens

Trigger: @combine:"id & & name", "id & ", "( )", "id & name" (two spaces — the second space terminates an empty key), or a ')' right after an operator: "id & )". errPrefix contains the offending remainder s.substring(i).

Common situations: Hand-written combine strings; concatenating optional parts so operators end up adjacent ("a & " + "& b"); double spaces after an operator because the grammar requires exactly one space each side and developers add more; leftover operators after deleting a key from a builder template.

Related errors


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