{"record":{"id":"ee8acb424b41ade6","repo":"OtterMind/Chat2DB","slug":"invalid-mongodb-what-name","errorCode":null,"errorMessage":"Invalid MongoDB {what}: {name}","messagePattern":"Invalid MongoDB (.+?): (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-mongodb/src/main/java/ai/chat2db/plugin/mongodb/MongodbSqlGuards.java","lineNumber":96,"sourceCode":"                        appendUnicodeEscape(sb, c);\n                    } else {\n                        sb.append(c);\n                    }\n            }\n        }\n        return sb.toString();\n    }\n\n    /**\n     * Escapes and surrounds one JSON/JavaScript string literal.\n     */\n    public static String quoteJsonString(String value) {\n        return value == null ? \"\\\"null\\\"\" : \"\\\"\" + escapeJsonString(value) + \"\\\"\";\n    }\n\n    private static void requireNonEmptyName(String name, String what) {\n        if (name == null || name.isEmpty() || name.indexOf('\\0') >= 0) {\n            throw new IllegalArgumentException(\"Invalid MongoDB \" + what + \": \" + name);\n        }\n    }\n\n    private static void appendUnicodeEscape(StringBuilder builder, char value) {\n        final char[] hex = \"0123456789abcdef\".toCharArray();\n        builder.append(\"\\\\u\")\n                .append(hex[(value >>> 12) & 0xf])\n                .append(hex[(value >>> 8) & 0xf])\n                .append(hex[(value >>> 4) & 0xf])\n                .append(hex[value & 0xf]);\n    }\n}\n","sourceCodeStart":78,"sourceCodeEnd":109,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-mongodb/src/main/java/ai/chat2db/plugin/mongodb/MongodbSqlGuards.java#L78-L109","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nString accessor = MongodbSqlGuards.collectionAccessor(meta.getName());\n\n// after\nString name = meta.getName();\nif (name == null || name.isEmpty() || name.indexOf('\\0') >= 0) {\n    continue; // skip invalid metadata rows\n}\nString accessor = MongodbSqlGuards.collectionAccessor(name);","handlingStrategy":"validation","validationCode":"if (name == null || name.isEmpty() || name.indexOf('\\0') >= 0) {\n    return; // skip invalid metadata rows\n}\nMongodbSqlGuards.collectionAccessor(name);","typeGuard":"static boolean isValidMongoName(String name) {\n    return name != null && !name.isEmpty() && name.indexOf('\\0') < 0;\n}","tryCatchPattern":"try {\n    MongodbSqlGuards.quoteFieldName(name);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Skipping field with invalid name\");\n}","preventionTips":["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."],"tags":["mongodb","validation","metadata"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}