{"record":{"id":"dbbdd75ce3090b45","repo":"t8y2/dbx","slug":"dropindexes-only-accepts-a-string-index-name-json","errorCode":null,"errorMessage":"dropIndexes only accepts a string index name, JSON document, or string array","messagePattern":"dropIndexes only accepts a string index name, JSON document, or string array","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":1419,"sourceCode":"            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) {\n        if (specification.size() != 1 || !specification.containsKey(\"_id\")) {\n            return false;\n        }\n        Object direction = specification.get(\"_id\");\n        if (direction instanceof Number number) {\n            return number.doubleValue() == 1.0;\n        }\n        // Document.parse turns Extended JSON $numberDecimal values into\n        // Decimal128, which does not implement Number in the legacy driver.\n        return direction instanceof Decimal128 decimal\n            && decimal.bigDecimalValue().compareTo(BigDecimal.ONE) == 0;\n    }\n\n    private static List<IndexInfo> listIndexInfos(MongoClient c, String database, String collection) {\n        List<IndexInfo> result = new ArrayList<>();","sourceCodeStart":1401,"sourceCodeEnd":1437,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L1401-L1437","documentation":"dropIndexes accepts a string name, a JSON-object key specification, or a JSON array of string names. This error is the final fall-through: the argument parsed to a JSON type outside all three accepted shapes. It is the multi-drop counterpart of the dropIndex type rejection.","triggerScenarios":"Calling dropIndexes with '123', 'true', 'null', or any other JSON value that is not a string, object, or array. Also occurs when the JSON itself fails to be any recognizable spec because of serialization mistakes in the caller.","commonSituations":"Template/ORM layers that substitute a variable directly and produce an unquoted literal; clients sending raw numbers or booleans copied from another API's parameter style; copy-paste of dropIndex arguments into dropIndexes without adapting the shape.","solutions":["Pass a JSON array of string names: dropIndexes(\"[\\\"idx_a\\\",\\\"idx_b\\\"]\")","Or a single string name, or an object specification, depending on the intent","Validate the argument parses to a string/object/array before invoking the tool"],"exampleFix":"// before\nagent.dropIndexes(\"42\");\n// after\nagent.dropIndexes(\"[\\\"email_idx\\\", \\\"age_1\\\"]\");","handlingStrategy":"type-guard","validationCode":"const okShape = (v) => typeof v === 'string' ||\n  (Array.isArray(v) && v.every(x => typeof x === 'string')) ||\n  (v !== null && typeof v === 'object' && !Array.isArray(v));\nif (!okShape(arg)) throw new Error('dropIndexes arg must be a string name, object spec, or string array');","typeGuard":"const isDropIndexesShape = (v) =>\n  typeof v === 'string' ||\n  (Array.isArray(v) && v.every(x => typeof x === 'string')) ||\n  (v !== null && typeof v === 'object' && !Array.isArray(v));","tryCatchPattern":"try {\n  agent.dropIndexes(arg);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"dropIndexes only accepts a string index name\")) {\n    log.error('dropIndexes got unsupported JSON type', { arg });\n  } else throw e;\n}","preventionTips":["Always serialize arguments through a JSON encoder rather than string templates","Validate the JSON shape before invoking the tool","Reuse one helper for building dropIndexes payloads"],"tags":["mongodb","argument-validation","dropindexes","type-error"],"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-14T05:17:10.506Z"}