{"record":{"id":"a74fbcb0d45757d1","repo":"t8y2/dbx","slug":"index-name-is-required","errorCode":null,"errorMessage":"Index name is required","messagePattern":"Index name is required","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":1376,"sourceCode":"        MongoClient c = requireClient();\n        String database = params.get(\"database\").getAsString();\n        c.getDatabase(database).drop();\n        return Collections.singletonMap(\"ok\", true);\n    }\n\n    static Object parseDropIndexesValue(String indexesJson, boolean single) {\n        if (indexesJson == null || indexesJson.isBlank()) {\n            if (single) {\n                throw new IllegalArgumentException(\"dropIndex requires a string index name or JSON document\");\n            }\n            return \"*\";\n        }\n\n        JsonElement value = JsonParser.parseString(indexesJson);\n        if (value.isJsonPrimitive() && value.getAsJsonPrimitive().isString()) {\n            String name = value.getAsString();\n            if (name.isBlank()) {\n                throw new IllegalArgumentException(\"Index name is required\");\n            }\n            if (single && \"*\".equals(name)) {\n                throw new IllegalArgumentException(\"dropIndex does not accept \\\"*\\\"; use dropIndexes() or dropIndexes(\\\"*\\\") instead\");\n            }\n            if (DEFAULT_ID_INDEX_NAME.equals(name)) {\n                throw new IllegalArgumentException(\"The default MongoDB _id_ index cannot be dropped\");\n            }\n            return name;\n        }\n        if (value.isJsonObject()) {\n            JsonObject object = value.getAsJsonObject();\n            if (object.size() == 0) {\n                throw new IllegalArgumentException(\"Index specification is required\");\n            }\n            Document specification = Document.parse(indexesJson);\n            if (isDefaultIdIndexSpecification(specification)) {\n                throw new IllegalArgumentException(\"The default MongoDB _id_ index cannot be dropped\");\n            }","sourceCodeStart":1358,"sourceCodeEnd":1394,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L1358-L1394","documentation":"When dropIndex receives a JSON string primitive as the index identifier, that string must be a non-blank index name. A whitespace/empty string cannot identify an index, so the agent throws immediately.","triggerScenarios":"Calling dropIndex with indexes=\"\" (after parsing as a JSON string, e.g. '\"\"' or a blank value), producing a blank name after JsonParser treats it as a string primitive.","commonSituations":"Empty environment variable or config field interpolated into the indexes parameter; trimming logic leaving whitespace; UI form submitted without the index name.","solutions":["Supply the actual index name, e.g. \"userId_1_createdAt_-1\"","Resolve the index name via listIndexes if unknown","Add a caller-side blank check before invoking dropIndex"],"exampleFix":"// before\nString index = env.get(\"DROP_INDEX\"); // \"\"\nagent.execute(\"dropIndex\", Map.of(\"indexes\", index));\n// after\nString index = env.get(\"DROP_INDEX\");\nif (index != null && !index.isBlank()) {\n    agent.execute(\"dropIndex\", Map.of(\"indexes\", index));\n}","handlingStrategy":"validation","validationCode":"if (indexName == null || indexName.isBlank()) {\n    throw new IllegalArgumentException(\"index name must be non-blank\");\n}\nparams.addProperty(\"indexes\", indexName);","typeGuard":"boolean isValidIndexName(String name) {\n    return name != null && !name.isBlank();\n}","tryCatchPattern":"try {\n    agent.execute(\"dropIndex\", params);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"Index name is required\")) {\n        log.error(\"Resolved index name was blank; check configuration source\");\n    } else { throw e; }\n}","preventionTips":["Resolve unknown index names via listIndexes first","Trim and check config/env values before passing them as index names","Fail fast at config load time if an index name field is empty"],"tags":["validation","mongodb","indexes","arguments"],"backgroundTag":"invalid-argument-value","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}