OtterMind/Chat2DB · error · IllegalArgumentException
Invalid SUNDB index sort direction: {value}
Error message
Invalid SUNDB index sort direction: {value} What it means
Thrown by SUNDBSqlGuards.requireAscOrDesc when an index sort direction, after trimming, is neither ASC nor DESC. The validator canonicalizes to uppercase ASC/DESC and rejects anything else to block DDL injection.
Source
Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-sundb/src/main/java/ai/chat2db/plugin/sundb/SUNDBSqlGuards.java:52
List.of("DAY", "TO", "SECOND"), List.of("HOUR", "TO", "MINUTE"),
List.of("HOUR", "TO", "SECOND"), List.of("MINUTE", "TO", "SECOND"));
private SUNDBSqlGuards() {
}
/**
* Validates an index sort direction: only ASC/DESC are legal, returned in
* canonical uppercase. Anything else is rejected to block DDL injection.
*/
public static String requireAscOrDesc(String value) {
String trimmed = value == null ? "" : value.trim();
if ("ASC".equalsIgnoreCase(trimmed)) {
return "ASC";
}
if ("DESC".equalsIgnoreCase(trimmed)) {
return "DESC";
}
throw new IllegalArgumentException("Invalid SUNDB index sort direction: " + value);
}
/**
* Validates one complete DEFAULT expression. Nested calls, sequence
* expressions, operators, and quoted literals remain available while
* statement terminators, comments, unbalanced delimiters, top-level commas,
* and trailing column clauses are rejected.
*/
public static String requireDefaultValue(String defaultValue) {
String trimmed = StringUtils.trimToNull(defaultValue);
if (trimmed == null) {
throw invalid("DEFAULT expression", defaultValue);
}
scanExpression(trimmed, false, "DEFAULT expression");
return trimmed;
}
/**View on GitHub (pinned to 5ee1e990e7)
Solutions
- Pass only 'ASC' or 'DESC' (case-insensitive).
- Leave the direction unset/null at the source if SUNDB should use its default, but ensure the caller does not forward a blank to requireAscOrDesc.
- Normalize imported metadata to ASC/DESC before building the index.
Example fix
// before
col.setAscOrDesc("NULLS FIRST");
// -> Invalid SUNDB index sort direction
// after
col.setAscOrDesc("ASC"); Defensive patterns
Strategy: validation
Validate before calling
String v = value == null ? "" : value.trim();
if (!"ASC".equalsIgnoreCase(v) && !"DESC".equalsIgnoreCase(v)) {
throw new IllegalArgumentException("Reject SUNDB sort direction: " + value);
} Type guard
static boolean isValidSundbAscOrDesc(String v) {
return v != null && ("ASC".equalsIgnoreCase(v.trim()) || "DESC".equalsIgnoreCase(v.trim()));
} Prevention
- Pass only ASC/DESC.
- Do not forward NULLS ordering into the per-column direction field.
- Validate at the boundary.
When it happens
Trigger: Passing a non-null, non-blank sort-direction value that is not ASC or DESC (e.g. 'NULLS FIRST', 'A', a localized word). A null/blank input is normalized to '' and also fails.
Common situations: Metadata/UI supplying a placeholder or a direction SUNDB does not support per index column; cross-dialect import carrying NULLS ordering.
Related errors
- Unsupported VARCHAR unit: {unit}
- Unsupported SUNDB index null ordering: {nullOrder}
- Invalid DB2 index column ordering: {ascOrDesc}
- Invalid DM index sort direction: {value}
- DM index must contain at least one named column
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/9788826d8c5a2d68.
Report an issue: GitHub.