OtterMind/Chat2DB · error · IllegalArgumentException
Invalid MySQL bit literal: {value}
Error message
Invalid MySQL bit literal: {value} What it means
Thrown by MysqlSqlGuards.requireBitLiteral when the content of a b'...' bit literal (the digits only, without the b' wrapper which the template adds) fails ^[01]+$. Only binary digits are valid; any other character, an empty string, or null is rejected because it would produce malformed SQL in a non-escapable position.
Source
Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlSqlGuards.java:63
}
/**
* Validate a raw DEFAULT literal for numeric-ish columns (positions where quoting would change
* semantics). Accepts decimal/scientific numbers, hex and bit literals, TRUE/FALSE.
*/
public static String requireNumericDefault(String value) {
if (value == null || !NUMERIC_DEFAULT_PATTERN.matcher(value.trim()).matches()) {
throw new IllegalArgumentException("Invalid MySQL default value: " + value);
}
return value;
}
/**
* Validate content of a b'...' bit literal.
*/
public static String requireBitLiteral(String value) {
if (value == null || !BIT_LITERAL_PATTERN.matcher(value).matches()) {
throw new IllegalArgumentException("Invalid MySQL bit literal: " + value);
}
return value;
}
/**
* Validate the digits of a 0x... hex literal (the template adds the 0x prefix).
*/
public static String requireHexDigits(String value) {
if (value == null || !HEX_DIGITS_PATTERN.matcher(value).matches()) {
throw new IllegalArgumentException("Invalid MySQL hex digits: " + value);
}
return value;
}
/**
* True only when the value is a well-formed 0x... hex literal. Values that merely
* start with 0x but contain non-hex characters must not pass through into SQL raw.
*/View on GitHub (pinned to 5ee1e990e7)
Solutions
- Pass only the raw binary digits (e.g. '1010') to requireBitLiteral, not the b'...' wrapped form.
- Strip any b' prefix/' suffix and validate the remainder is purely 0/1 before calling.
- Reject empty/null bit values upstream with a clear message.
- If the source is decimal, convert to binary first or route through a different default path.
Example fix
// before
MysqlSqlGuards.requireBitLiteral(rawBits);
// after
String bits = StringUtils.trimToNull(rawBits);
if (bits != null && bits.startsWith("b'") && bits.endsWith("'")) {
bits = bits.substring(2, bits.length() - 1);
}
if (bits == null || !bits.matches("^[01]+$")) {
throw new IllegalArgumentException("Invalid MySQL bit literal: " + rawBits);
}
MysqlSqlGuards.requireBitLiteral(bits); Defensive patterns
Strategy: validation
Validate before calling
String bits = StringUtils.trimToNull(value);
if (bits != null && bits.startsWith("b'") && bits.endsWith("'")) {
bits = bits.substring(2, bits.length() - 1);
}
if (bits == null || !bits.matches("^[01]+$")) {
throw new IllegalArgumentException("Invalid MySQL bit literal: " + value);
}
MysqlSqlGuards.requireBitLiteral(bits); Type guard
static boolean isBitLiteral(String value) {
return value != null && value.matches("^[01]+$");
} Prevention
- Pass only the inner binary digits, not the b'...' wrapper.
- Strip a b' prefix/' suffix before validation.
- Reject empty bit values upstream.
- Convert decimal inputs to binary before treating them as bits.
When it happens
Trigger: Calling requireBitLiteral(value) with a string containing characters other than 0 and 1, an empty string, or null. The caller must pass only the inner digits, not the full b'0101' literal.
Common situations: Passing the full b'1010' literal instead of just '1010'; a UI bit-field allowing hex characters; a value parsed from JSON where a string defaulted to a non-binary placeholder; passing a decimal number's digits to a BIT column.
Related errors
- Invalid MySQL {what}: {value}
- Invalid MySQL default value: {value}
- Invalid MySQL hex digits: {value}
- Invalid MySQL definer: {value}
- Invalid MySQL column type: {value}
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/01bfa5f6a1397795.
Report an issue: GitHub.