{"record":{"id":"2487d76802ca22da","repo":"t8y2/dbx","slug":"dropindexes-only-accepts-non-empty-string-arrays","errorCode":null,"errorMessage":"dropIndexes only accepts non-empty string arrays","messagePattern":"dropIndexes only accepts non-empty string arrays","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":1409,"sourceCode":"            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) {\n        if (specification.size() != 1 || !specification.containsKey(\"_id\")) {\n            return false;\n        }\n        Object direction = specification.get(\"_id\");\n        if (direction instanceof Number number) {","sourceCodeStart":1391,"sourceCodeEnd":1427,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L1391-L1427","documentation":"dropIndexes rejects an empty JSON array. Dropping zero indexes is treated as a caller mistake rather than a no-op, so the library fails fast with this message to prevent silently doing nothing when an array was intended to contain names.","triggerScenarios":"Calling dropIndexes with '[]' or a JSON expression that parses to an empty array (e.g. an empty list serialized by upstream code). The names list ends up empty after validating the elements, triggering this throw.","commonSituations":"Application code builds a list of indexes to drop conditionally and all conditions were false, producing []; template-driven tooling that serializes an empty collection; refactoring where the list-population logic was accidentally removed.","solutions":["Check the array before calling: only invoke dropIndexes when at least one index name is present","If dropping zero indexes is legitimately possible, guard the call with an isEmpty check and skip it","Verify the code that builds the name list is actually populating it"],"exampleFix":"// before\nagent.dropIndexes(indexNamesJson); // may be \"[]\"\n// after\nif (!indexNames.isEmpty()) {\n    agent.dropIndexes(toJsonArray(indexNames));\n}","handlingStrategy":"validation","validationCode":"if (Array.isArray(pendingNames) && pendingNames.length === 0) {\n  return { dropped: [] }; // no-op instead of calling dropIndexes([])\n}","typeGuard":"const isNonEmptyStringArray = (v) =>\n  Array.isArray(v) && v.length > 0;","tryCatchPattern":"try {\n  agent.dropIndexes(json);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().includes(\"non-empty string arrays\")) {\n    log.info('Nothing to drop; empty index list');\n  } else throw e;\n}","preventionTips":["Guard the call site: skip dropIndexes when the collected list is empty","Trace the list-building code path when you get empty arrays","Log the serialized payload before sending for easier debugging"],"tags":["mongodb","argument-validation","dropindexes","empty-input"],"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"}