Tencent/APIJSON · error · IllegalArgumentException

字符串 {alias} 不合法!预编译模式下 {key}:value 中 value里面用 ; 分割的每一项 funct

Error message

字符串 {alias} 不合法!预编译模式下 {key}:value 中 value里面用 ; 分割的每一项 function(arg0,arg1,...):alias 中 alias 必须是1个单词!并且不要有多余的空格!

What it means

After a function call in an @column-style expression, the text after the last ')' is split at the last ':' into suffix and alias; when allowAlias is true (GET @column) and the alias is non-empty but fails StringUtil.isName, this IllegalArgumentException is thrown. Aliases must be exactly one identifier word with no spaces.

Source

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

				}

				String s = expression.substring(start + 1, end);
				boolean distinct = s.startsWith(PREFIX_DISTINCT);
				if (distinct) {
					s = s.substring(PREFIX_DISTINCT.length());
				}

				// 解析函数内的参数
				String ckeys[] = parseArgsSplitWithComma(s, false, containRaw, allowAlias);

				String suffix = expression.substring(end + 1); //:contactCount
				String alias = null;
				if (allowAlias) {
					int index = suffix.lastIndexOf(":");
					alias = index < 0 ? "" : suffix.substring(index + 1); //contactCount
					suffix = index < 0 ? suffix : suffix.substring(0, index);
					if (alias.isEmpty() == false && StringUtil.isName(alias) == false) {
						throw new IllegalArgumentException("字符串 " + alias + " 不合法!预编译模式下 "
								+ key + ":value 中 value里面用 ; 分割的每一项"
								+ " function(arg0,arg1,...):alias 中 alias 必须是1个单词!并且不要有多余的空格!");
					}
				}

				if (suffix.isEmpty() == false && (suffix.contains("--") || suffix.contains("/*")
						|| PATTERN_RANGE.matcher(suffix).matches() == false)) {
					throw new UnsupportedOperationException("字符串 " + suffix + " 不合法!预编译模式下 " + key
							+ ":\"column?value;function(arg0,arg1,...)?value...\""
							+ " 中 ?value 必须符合正则表达式 " + PATTERN_RANGE + " 且不包含连续减号 -- 或注释符 /* !不允许多余的空格!");
				}

				String origin = fun + "(" + (distinct ? PREFIX_DISTINCT : "") + StringUtil.get(ckeys) + ")" + suffix;
				expression = origin + (StringUtil.isEmpty(alias, true) ? "" : gainAs() + quote + alias + quote);
			}
			else {
				//是窗口函数   fun(arg0,agr1) OVER (agr0 agr1 ...)
				int keyIndex = containOver ? overIndex : againstIndex;

View on GitHub (pinned to 5284052872)

Solutions

  1. Use a single-word alias: "sum(id):totalAmount".
  2. Remove all spaces around the ':'.
  3. Keep ':' out of the suffix; if a format string needs ':', put the whole expression in @raw.
  4. Omit the alias entirely if you do not need one.

Example fix

// before
{"User":{"@column":"sum(id):total count"}}
// after
{"User":{"@column":"sum(id):totalCount"}}
Defensive patterns

Strategy: validation

Validate before calling

const NAME=/^[A-Za-z][A-Za-z0-9_]*$/;
const tail=expr.slice(expr.lastIndexOf(')')+1);
const i=tail.lastIndexOf(':');
if(i>=0&&tail.slice(i+1)&&!NAME.test(tail.slice(i+1)))throw new Error('alias must be one word');

Type guard

null

Try / catch

catch IllegalArgumentException; sanitize alias and retry

Prevention

When it happens

Trigger: "@column":"concat(a,b):my name" (space in alias), "@column":"sum(id):total-amount" (hyphen), or a suffix colon from a format string being mistaken for an alias separator in malformed variants of date_format expressions.

Common situations: Developer wants a human-readable alias with spaces or punctuation; format strings inside the suffix introduce extra ':' characters; spaces copied from SQL 'AS my alias'.

Related errors


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