{"record":{"id":"01bfa5f6a1397795","repo":"OtterMind/Chat2DB","slug":"invalid-mysql-bit-literal-value","errorCode":null,"errorMessage":"Invalid MySQL bit literal: {value}","messagePattern":"Invalid MySQL bit literal: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlSqlGuards.java","lineNumber":63,"sourceCode":"    }\n\n    /**\n     * Validate a raw DEFAULT literal for numeric-ish columns (positions where quoting would change\n     * semantics). Accepts decimal/scientific numbers, hex and bit literals, TRUE/FALSE.\n     */\n    public static String requireNumericDefault(String value) {\n        if (value == null || !NUMERIC_DEFAULT_PATTERN.matcher(value.trim()).matches()) {\n            throw new IllegalArgumentException(\"Invalid MySQL default value: \" + value);\n        }\n        return value;\n    }\n\n    /**\n     * Validate content of a b'...' bit literal.\n     */\n    public static String requireBitLiteral(String value) {\n        if (value == null || !BIT_LITERAL_PATTERN.matcher(value).matches()) {\n            throw new IllegalArgumentException(\"Invalid MySQL bit literal: \" + value);\n        }\n        return value;\n    }\n\n    /**\n     * Validate the digits of a 0x... hex literal (the template adds the 0x prefix).\n     */\n    public static String requireHexDigits(String value) {\n        if (value == null || !HEX_DIGITS_PATTERN.matcher(value).matches()) {\n            throw new IllegalArgumentException(\"Invalid MySQL hex digits: \" + value);\n        }\n        return value;\n    }\n\n    /**\n     * True only when the value is a well-formed 0x... hex literal. Values that merely\n     * start with 0x but contain non-hex characters must not pass through into SQL raw.\n     */","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlSqlGuards.java#L45-L81","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nMysqlSqlGuards.requireBitLiteral(rawBits);\n\n// after\nString bits = StringUtils.trimToNull(rawBits);\nif (bits != null && bits.startsWith(\"b'\") && bits.endsWith(\"'\")) {\n    bits = bits.substring(2, bits.length() - 1);\n}\nif (bits == null || !bits.matches(\"^[01]+$\")) {\n    throw new IllegalArgumentException(\"Invalid MySQL bit literal: \" + rawBits);\n}\nMysqlSqlGuards.requireBitLiteral(bits);","handlingStrategy":"validation","validationCode":"String bits = StringUtils.trimToNull(value);\nif (bits != null && bits.startsWith(\"b'\") && bits.endsWith(\"'\")) {\n    bits = bits.substring(2, bits.length() - 1);\n}\nif (bits == null || !bits.matches(\"^[01]+$\")) {\n    throw new IllegalArgumentException(\"Invalid MySQL bit literal: \" + value);\n}\nMysqlSqlGuards.requireBitLiteral(bits);","typeGuard":"static boolean isBitLiteral(String value) {\n    return value != null && value.matches(\"^[01]+$\");\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["mysql","validation","ddl","bit-literal"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}