Tencent/APIJSON · error · IllegalArgumentException

参数 {} 不合法!key 中不允许有单引号 ' !

Error message

参数 {} 不合法!key 中不允许有单引号 ' !

What it means

Thrown by gainKey only when isTest() is true: the key contains a single quote character. In test mode the library passes keys through gainSQLValue directly (no prepared-statement placeholder path), so a quote could break out of the string and is rejected as an SQL-injection guard.

Source

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

		}

		return gainKey(column) + " " + type + " " + (value instanceof Subquery ? gainSubqueryString((Subquery<T, M, L>) value)
				: (rawSQL != null ? rawSQL : gainValue(key, column, value)));
	}

	public String gainKey(@NotNull String key) {
		String lenFun = "";
		if (key.endsWith("[")) {
			lenFun = isSQLServer() || isKingBaseSQLServer() ? "datalength" : "length";
			key = key.substring(0, key.length() - 1);
		}
		else if (key.endsWith("{")) {
			lenFun = "json_length";
			key = key.substring(0, key.length() - 1);
		}
		else if (isTest()) {
			if (key.contains("'")) {  // || key.contains("#") || key.contains("--")) {
				throw new IllegalArgumentException("参数 " + key + " 不合法!key 中不允许有单引号 ' !");
			}
			return gainSQLValue(key).toString();
		}

		Map<String, String> keyMap = getKeyMap();
		String expression = keyMap == null ? null : keyMap.get(key);
		if (expression == null) {
			expression = COLUMN_KEY_MAP == null ? null : COLUMN_KEY_MAP.get(key);
		}

		String sqlKey;
		if (expression == null) {
			sqlKey = gainSQLKey(key);
		}
		else {
			// (name,tag) left(date,4) 等
			List<String> raw = getRaw();
			sqlKey = parseSQLExpression(KEY_KEY, expression, raw != null && raw.contains(KEY_KEY), false);

View on GitHub (pinned to 5284052872)

Solutions

  1. Remove single quotes from keys/values; escape or drop them client-side.
  2. If the quote is legitimate data, pass it as a prepared value (condition value), not as part of the key.
  3. Verify isTest() is not accidentally enabled in production or CI configuration.

Example fix

// before
{"User": {"name'": "az"}}
// after
{"User": {"name": "az"}}
Defensive patterns

Strategy: validation

Validate before calling

if (isTestMode && key.includes("'")) throw new Error("key must not contain a single quote in test mode");

Prevention

When it happens

Trigger: Running with the test/debug flag enabled (isTest()) and sending a condition key or @column expression containing ' — e.g. dynamically built keys like "name'" or raw column fragments with quotes.

Common situations: Unit/integration tests that enable test mode and then feed user-controlled key strings; leftover isTest configuration in a deployment pipeline.

Related errors


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