{"record":{"id":"f5e738c31d39f432","repo":"t8y2/dbx","slug":"index-specification-is-required","errorCode":null,"errorMessage":"Index specification is required","messagePattern":"Index specification 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":1389,"sourceCode":"\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            }\n            return specification;\n        }\n        if (value.isJsonArray()) {\n            if (single) {\n                throw new IllegalArgumentException(\"dropIndex only accepts a string index name or JSON document; arrays are not supported\");\n            }\n            List<String> names = new ArrayList<>();\n            value.getAsJsonArray().forEach(item -> {\n                if (!item.isJsonPrimitive() || !item.getAsJsonPrimitive().isString() || item.getAsString().isBlank()) {\n                    throw new IllegalArgumentException(\"dropIndexes only accepts arrays of string index names\");\n                }\n                names.add(item.getAsString());\n            });","sourceCodeStart":1371,"sourceCodeEnd":1407,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L1371-L1407","documentation":"If the dropIndex/dropIndexes argument parses to a JSON object (a key-pattern index specification), that object must contain at least one key. An empty document {} cannot identify any index, so the agent throws before issuing the drop command.","triggerScenarios":"Calling dropIndex/dropIndexes with indexes=\"{}\" or an object serialized from an empty map (e.g. JSON.stringify({}) from a JS caller, or an unset map variable).","commonSituations":"Building the key pattern dynamically and the underlying map ending up empty; partial deserialization dropping all keys; templating placeholder replaced with an empty object.","solutions":["Provide the key pattern of the index, e.g. {\"createdAt\": 1}","Confirm the map/object used to build the spec is populated","Prefer passing the index name string from listIndexes when known"],"exampleFix":"// before\nMap<String,Integer> keys = indexKeysFromConfig(); // may be empty\nagent.execute(\"dropIndex\", Map.of(\"indexes\", gson.toJson(keys)));\n// after\nMap<String,Integer> keys = indexKeysFromConfig();\nif (!keys.isEmpty()) {\n    agent.execute(\"dropIndex\", Map.of(\"indexes\", gson.toJson(keys)));\n} else {\n    throw new IllegalStateException(\"index key pattern not configured\");\n}","handlingStrategy":"validation","validationCode":"Document keyPattern = Document.parse(indexesJson);\nif (keyPattern.isEmpty()) {\n    throw new IllegalArgumentException(\"index key pattern must have at least one key\");\n}","typeGuard":"boolean isNonEmptyKeySpec(Map<String,?> keys) {\n    return keys != null && !keys.isEmpty();\n}","tryCatchPattern":"try {\n    agent.execute(\"dropIndex\", params);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Index specification is required\")) {\n        throw new IllegalStateException(\"configured key pattern was empty\", e);\n    } else { throw e; }\n}","preventionTips":["Assert the key-pattern map is populated before serialization","Avoid building specs from unset/optional config sections","Prefer index names from listIndexes over hand-built key patterns"],"tags":["validation","mongodb","indexes","arguments"],"backgroundTag":"missing-required-argument","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"}