{"record":{"id":"77fcda690f2a5101","repo":"OtterMind/Chat2DB","slug":"invalid-mysql-column-type-value","errorCode":null,"errorMessage":"Invalid MySQL column type: {value}","messagePattern":"Invalid MySQL column type: (.+?)","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":103,"sourceCode":"\n    /**\n     * Validate a DEFINER value (user@host, parts optionally single-quoted or backtick-quoted).\n     */\n    public static String requireDefiner(String value) {\n        if (value == null || !DEFINER_PATTERN.matcher(value).matches()) {\n            throw new IllegalArgumentException(\"Invalid MySQL definer: \" + value);\n        }\n        return value;\n    }\n\n    /**\n     * Validate a fallback column type expression while preserving common custom type names,\n     * optional numeric precision/scale and keyword modifiers.\n     */\n    public static String requireColumnType(String value) {\n        String trimmed = StringUtils.trimToEmpty(value);\n        if (!COLUMN_TYPE_PATTERN.matcher(trimmed).matches()) {\n            throw new IllegalArgumentException(\"Invalid MySQL column type: \" + value);\n        }\n        return trimmed;\n    }\n\n    /**\n     * Validate an index sort direction: only ASC/DESC are legal, returned in canonical uppercase.\n     */\n    public static String requireAscOrDesc(String value) {\n        String trimmed = StringUtils.trimToEmpty(value);\n        if (\"ASC\".equalsIgnoreCase(trimmed)) {\n            return \"ASC\";\n        }\n        if (\"DESC\".equalsIgnoreCase(trimmed)) {\n            return \"DESC\";\n        }\n        throw new IllegalArgumentException(\"Invalid MySQL index sort direction: \" + value);\n    }\n","sourceCodeStart":85,"sourceCodeEnd":121,"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#L85-L121","documentation":"Thrown by MysqlSqlGuards.requireColumnType when a fallback column type expression fails COLUMN_TYPE_PATTERN. The pattern requires the type to start with a letter, allow [A-Za-z0-9_], an optional (precision[,scale]) group, and trailing keyword modifiers (each starting with a letter). It preserves custom type names while rejecting anything containing SQL metacharacters. The value is trimmed first.","triggerScenarios":"Calling requireColumnType(value) with a type containing parentheses with non-numeric content, a leading digit or symbol, embedded quotes/backticks, commas outside parentheses, or any char outside [A-Za-z0-9_ ()].","commonSituations":"A custom column type pasted with surrounding backticks or quotes; a type like 'VARCHAR(255) UNSIGNED' that is fine, versus 'int(10)`x`' that is not; a parameterized type where the precision contains letters; a type string concatenated from untrusted input.","solutions":["Trim the type and strip surrounding backticks/quotes before passing to requireColumnType.","Ensure precision/scale inside parentheses are numeric only.","Reject types with embedded SQL metacharacters upstream.","If the type is exotic, confirm it is a real MySQL type name and not an expression."],"exampleFix":"// before\nMysqlSqlGuards.requireColumnType(columnType);\n\n// after\nString t = StringUtils.trimToEmpty(columnType);\nif (!t.matches(\"^[A-Za-z][A-Za-z0-9_]*(\\\\s*\\\\(\\\\s*\\\\d+(\\\\s*,\\\\s*\\\\d+)?\\\\s*\\\\))?(\\\\s+[A-Za-z][A-Za-z0-9_]*)*$\")) {\n    throw new IllegalArgumentException(\"Invalid MySQL column type: \" + columnType);\n}\nMysqlSqlGuards.requireColumnType(t);","handlingStrategy":"validation","validationCode":"String t = StringUtils.trimToEmpty(value);\nif (!t.matches(\"^[A-Za-z][A-Za-z0-9_]*(\\\\s*\\\\(\\\\s*\\\\d+(\\\\s*,\\\\s*\\\\d+)?\\\\s*\\\\))?(\\\\s+[A-Za-z][A-Za-z0-9_]*)*$\")) {\n    throw new IllegalArgumentException(\"Invalid MySQL column type: \" + value);\n}\nMysqlSqlGuards.requireColumnType(t);","typeGuard":"static boolean isValidColumnType(String value) {\n    String t = StringUtils.trimToEmpty(value);\n    return t.matches(\"^[A-Za-z][A-Za-z0-9_]*(\\\\s*\\\\(\\\\s*\\\\d+(\\\\s*,\\\\s*\\\\d+)?\\\\s*\\\\))?(\\\\s+[A-Za-z][A-Za-z0-9_]*)*$\");\n}","tryCatchPattern":null,"preventionTips":["Strip surrounding backticks/quotes from type names before validation.","Keep precision/scale inside parentheses numeric only.","Reject types with embedded SQL metacharacters at the boundary.","Confirm exotic types are real MySQL type names, not expressions."],"tags":["mysql","validation","ddl","column-type"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}