Tencent/APIJSON · error · IllegalArgumentException

{errPrefix} 中字符 '{s}' 不合法!其中 key 数量 {allCount} / 条件键值对数量 {si

Error message

{errPrefix} 中字符 '{s}' 不合法!其中 key 数量 {allCount} / 条件键值对数量 {size} = {allCount/size} 已超过 最大倍数,必须在条件键值对数量 0-{maxCombineRatio} 倍内!

What it means

After each accepted key in @combine, the ratio allCount/size (referenced keys vs. total condition pairs) is compared to maxCombineRatio. Exceeding it throws. This complements error 150: instead of an absolute cap, it bounds how top-heavy an expression is relative to the condition map — a protection against expressions that reference a few keys an enormous number of times (e.g. giant generated formulas), which is a parse-time DoS vector.

Source

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

						int keyIndex = column.indexOf(":");
						column = keyIndex > 0 ? column.substring(0, keyIndex) : column;
						Object value = conditionMap.get(column);
						String wi = "";
						if (value == null && conditionMap.containsKey(column) == false) { // 兼容@null
							isNot = false; // 以占位表达式为准
							size++; // 兼容 key 数量判断
							wi = keyIndex > 0 ? key.substring(keyIndex + 1) : "";
							if (StringUtil.isEmpty(wi)) {
								throw new IllegalArgumentException(errPrefix + " 中字符 '"
										+ key + "' 对应的条件键值对 " + column + ":value 不存在!");
							}
						} else {
							wi = isHaving ? gainHavingItem(quote, table, alias, column, (String) value, containRaw)
									: gainWhereItem(column, value, method, verifyName);
						}

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

						if (StringUtil.isEmpty(wi, true)) {  // 转成 1=1 ?
							throw new IllegalArgumentException(errPrefix + " 中字符 '" + key
									+ "' 对应的 " + column + ":value 不是有效条件键值对!");
						}

						Integer count = usedKeyCountMap.get(column);
						count = count == null ? 1 : count + 1;
						if (count > maxCombineKeyCount && maxCombineKeyCount > 0) {
							throw new IllegalArgumentException(errPrefix + " 中字符 '" + s + "' 不合法!"
									+ "其中 '" + column + "' 重复引用,次数 " + count
									+ " 已超过最大值,必须在 0-" + maxCombineKeyCount + " 内!");
						}
						usedKeyCountMap.put(column, count);

View on GitHub (pinned to 5284052872)

Solutions

  1. Reference each key once (or a few times); do not repeat keys in @combine.
  2. Raise maxCombineRatio in server config if the workload legitimately reuses keys heavily.
  3. Simplify the logic — deeply repeated terms usually reduce via parentheses reordering or by moving fixed conditions out of @combine (unstated keys default to AND).

Example fix

// before
{"@combine":"a & a & a & a & a & a | b"}
// after
{"@combine":"a | b","c":1,"d":1}
Defensive patterns

Strategy: validation

Validate before calling

int refs = combine.split("[&|]", -1).length; // per-term references
int size = condKeys.size();
if (MAX_COMBINE_RATIO > 0 && (float) refs / size > MAX_COMBINE_RATIO) throw new IllegalStateException("combine ratio too high");

Type guard

function withinRatio(refs: number, size: number, max: number): boolean { return max <= 0 || refs / size <= max; }

Try / catch

catch (IllegalArgumentException e) { /* simplify expression, remove repeated key references, retry */ }

Prevention

When it happens

Trigger: A condition map of size 3 ("a","b","c") with @combine:"a & a & a & a ... & b | c" — allCount grows per reference, size stays 3; once allCount/3 > maxCombineRatio (e.g. 5.0) it throws. size can also be incremented on the fly for placeholder keys (the size++ for @null-compat), slightly changing the ratio.

Common situations: Repeating the same key many times in generated expressions; low maxCombineRatio configured server-side after hardening; upgrading APIJSON to a version that introduced ratio limits so previously-working requests start failing.

Related errors


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