{"record":{"id":"163ac2cebf73b764","repo":"OtterMind/Chat2DB","slug":"invalid-mysql-index-sort-direction-value","errorCode":null,"errorMessage":"Invalid MySQL index sort direction: {value}","messagePattern":"Invalid MySQL index sort direction: (.+?)","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":119,"sourceCode":"        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\n    /**\n     * Validate an option that must be one of the given enum constants (e.g. view algorithm /\n     * sql security / check option). Returns the canonical enum name.\n     */\n    public static <E extends Enum<E>> String requireEnumConstant(String value, E[] constants, String what) {\n        for (E constant : constants) {\n            if (constant.name().equalsIgnoreCase(StringUtils.trimToEmpty(value))) {\n                return constant.name();\n            }\n        }\n        throw new IllegalArgumentException(\"Invalid MySQL \" + what + \": \" + value);\n    }\n\n    /**\n     * Parse and re-escape a comma-separated ENUM/SET value list. Quoted values are decoded before\n     * they are escaped again, so metadata such as {@code 'can''t'} is not double-escaped. A","sourceCodeStart":101,"sourceCodeEnd":137,"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#L101-L137","documentation":"Thrown by MysqlSqlGuards.requireAscOrDesc when an index column sort direction is not ASC or DESC (matched case-insensitively after trim). Only those two directions are legal MySQL index sort keywords; the function returns the canonical uppercase form. Null, empty, or any other value is rejected.","triggerScenarios":"Calling requireAscOrDesc(value) with null, an empty string, 'NONE', 'ASCENDING', or any token other than ASC/DESC.","commonSituations":"A UI index builder defaulting direction to null/'NONE' for non-sorted columns; the value not set when the user leaves the direction dropdown empty; an API payload forwarding an unrecognised direction string.","solutions":["Only pass ASC or DESC to requireAscOrDesc; for columns without a direction, omit the call entirely.","If a null/empty direction means 'no sort', skip validation and do not emit a direction clause.","Map UI direction values to ASC/DESC/null at the boundary and branch on null.","Trim and upper-case the input before comparison."],"exampleFix":"// before\nMysqlSqlGuards.requireAscOrDesc(direction);\n\n// after\nString d = StringUtils.trimToNull(direction);\nString sortDir = d == null ? null : d.toUpperCase(Locale.ROOT);\nif (sortDir != null && !\"ASC\".equals(sortDir) && !\"DESC\".equals(sortDir)) {\n    throw new IllegalArgumentException(\"Invalid MySQL index sort direction: \" + direction);\n}\n// only guard when a direction is actually required:\nif (sortDir != null) {\n    MysqlSqlGuards.requireAscOrDesc(sortDir);\n}","handlingStrategy":"validation","validationCode":"String d = StringUtils.trimToNull(direction);\nif (d != null) {\n    String up = d.toUpperCase(Locale.ROOT);\n    if (!\"ASC\".equals(up) && !\"DESC\".equals(up)) {\n        throw new IllegalArgumentException(\"Invalid MySQL index sort direction: \" + direction);\n    }\n    MysqlSqlGuards.requireAscOrDesc(up);\n}","typeGuard":"static boolean isAscOrDesc(String value) {\n    String d = StringUtils.trimToEmpty(value).toUpperCase(Locale.ROOT);\n    return \"ASC\".equals(d) || \"DESC\".equals(d);\n}","tryCatchPattern":null,"preventionTips":["Only pass ASC or DESC; skip the call when no direction is needed.","Map UI direction values to ASC/DESC/null at the boundary.","Treat null/empty as 'no sort' rather than a value to guard.","Upper-case and trim before comparison."],"tags":["mysql","validation","ddl","index"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}