{"record":{"id":"b3f833da652648b8","repo":"t8y2/dbx","slug":"dropindexes-only-accepts-arrays-of-string-index-na","errorCode":null,"errorMessage":"dropIndexes only accepts arrays of string index names","messagePattern":"dropIndexes only accepts arrays of string index names","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":1404,"sourceCode":"        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            });\n            if (names.isEmpty()) {\n                throw new IllegalArgumentException(\"dropIndexes only accepts non-empty string arrays\");\n            }\n            if (names.contains(DEFAULT_ID_INDEX_NAME)) {\n                throw new IllegalArgumentException(\"The default MongoDB _id_ index cannot be dropped\");\n            }\n            return names;\n        }\n        if (single) {\n            throw new IllegalArgumentException(\"dropIndex only accepts a string index name or JSON document\");\n        }\n        throw new IllegalArgumentException(\"dropIndexes only accepts a string index name, JSON document, or string array\");\n    }\n\n    private static boolean isDefaultIdIndexSpecification(Document specification) {","sourceCodeStart":1386,"sourceCodeEnd":1422,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L1386-L1422","documentation":"When dropIndexes receives a JSON array, every element must be a non-blank JSON string index name. This error means at least one array element was not a string (e.g. an object or number) or was blank/whitespace. dropIndexes arrays cannot contain index-key specification objects.","triggerScenarios":"Calling dropIndexes with an array containing non-string or blank elements, e.g. '[\"email_idx\", {\"age\": 1}]', '[\"email_idx\", \"\"]', or '[123]'. The forEach lambda throws on the first offending element.","commonSituations":"Mixing index names and index-key documents in one dropIndexes call; building the JSON array programmatically where empty/null strings slip in; users assuming dropIndexes accepts key-spec objects like dropIndex does.","solutions":["Ensure every element of the array is a plain string index name (use listIndexes to get the names)","Remove empty or whitespace-only strings from the array","To drop by key specification, resolve the actual index name via listIndexes first, then drop by that name"],"exampleFix":"// before\nagent.dropIndexes(\"[\\\"email_idx\\\", {\\\"age\\\": 1}, \\\"\\\"]\");\n// after\nagent.dropIndexes(\"[\\\"email_idx\\\", \\\"age_1\\\"]\");","handlingStrategy":"validation","validationCode":"function assertDropIndexesArray(names) {\n  if (!Array.isArray(names) || names.length === 0) return;\n  for (const n of names) {\n    if (typeof n !== 'string' || n.trim() === '')\n      throw new Error('dropIndexes array must contain only non-empty string index names, got: ' + JSON.stringify(n));\n  }\n}","typeGuard":"const isStringNameArray = (v) =>\n  Array.isArray(v) && v.length > 0 && v.every(n => typeof n === 'string' && n.trim() !== '');","tryCatchPattern":"try {\n  agent.dropIndexes(json);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"dropIndexes only accepts arrays of string index names\")) {\n    const names = await resolveIndexNamesFromListIndexes();\n    agent.dropIndexes(JSON.stringify(names.filter(n => typeof n === 'string' && n)));\n  } else throw e;\n}","preventionTips":["Resolve index names via listIndexes rather than constructing key-spec objects in arrays","Sanitize array elements: trim and drop empties before serializing","Never mix name strings and spec objects in a dropIndexes array"],"tags":["mongodb","argument-validation","dropindexes"],"backgroundTag":"invalid-argument-type","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}