OtterMind/Chat2DB · error · IllegalArgumentException
Invalid MongoDB {what}: {name}
Error message
Invalid MongoDB {what}: {name} What it means
Thrown by the private requireNonEmptyName helper, used by collectionAccessor('collection name') and quoteFieldName('field name'). It rejects null, empty strings, and any name containing a NUL byte (\0). Unlike requireDatabaseName it allows most characters because collection/field names are JSON-quoted and escaped; it only guards against the degenerate cases that cannot be safely interpolated.
Source
Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-mongodb/src/main/java/ai/chat2db/plugin/mongodb/MongodbSqlGuards.java:96
appendUnicodeEscape(sb, c);
} else {
sb.append(c);
}
}
}
return sb.toString();
}
/**
* Escapes and surrounds one JSON/JavaScript string literal.
*/
public static String quoteJsonString(String value) {
return value == null ? "\"null\"" : "\"" + escapeJsonString(value) + "\"";
}
private static void requireNonEmptyName(String name, String what) {
if (name == null || name.isEmpty() || name.indexOf('\0') >= 0) {
throw new IllegalArgumentException("Invalid MongoDB " + what + ": " + name);
}
}
private static void appendUnicodeEscape(StringBuilder builder, char value) {
final char[] hex = "0123456789abcdef".toCharArray();
builder.append("\\u")
.append(hex[(value >>> 12) & 0xf])
.append(hex[(value >>> 8) & 0xf])
.append(hex[(value >>> 4) & 0xf])
.append(hex[value & 0xf]);
}
}
View on GitHub (pinned to 5ee1e990e7)
Solutions
- Null-check collection/field names before invoking the guard and skip or skip-with-default those entries.
- Filter out or reject empty/blank names at the request-parsing boundary.
- Sanitize binary-derived names by stripping or rejecting NUL bytes before formatting shell text.
- Log the originating query when the error occurs to find which metadata row produced the bad name.
Example fix
// before
String accessor = MongodbSqlGuards.collectionAccessor(meta.getName());
// after
String name = meta.getName();
if (name == null || name.isEmpty() || name.indexOf('\0') >= 0) {
continue; // skip invalid metadata rows
}
String accessor = MongodbSqlGuards.collectionAccessor(name); Defensive patterns
Strategy: validation
Validate before calling
if (name == null || name.isEmpty() || name.indexOf('\0') >= 0) {
return; // skip invalid metadata rows
}
MongodbSqlGuards.collectionAccessor(name); Type guard
static boolean isValidMongoName(String name) {
return name != null && !name.isEmpty() && name.indexOf('\0') < 0;
} Try / catch
try {
MongodbSqlGuards.quoteFieldName(name);
} catch (IllegalArgumentException e) {
log.warn("Skipping field with invalid name");
} Prevention
- Null-check names returned by metadata fetches before formatting shell text.
- Reject blank field names at the JSON-parsing boundary.
- Sanitize binary-derived names that may contain NUL bytes.
- Skip rather than crash when a single metadata row is malformed.
When it happens
Trigger: Calling MongodbSqlGuards.collectionAccessor(name) or quoteFieldName(name) with a null argument, an empty string, or a string that contains a NUL character (often a sign of truncated/corrupted C-string data or a malformed request payload).
Common situations: A metadata fetch returns null for a collection name (e.g. a system namespace that has no friendly name); a field name comes from a user-built JSON where a key was left blank; binary data containing NUL bytes leaks into a name field.
Related errors
- Unsafe column type name from metadata: {typeName}
- Unsafe H2 column default from metadata: {columnDefault}
- Missing JDBC type for Kylin column: {name}
- Unsupported Kylin JDBC column type: {jdbcType}
- Missing JDBC type name for Kylin ARRAY column: {name}
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/ee8acb424b41ade6.
Report an issue: GitHub.