t8y2/dbx · error · java.lang.IllegalArgumentException
dropIndexes only accepts non-empty string arrays
Error message
dropIndexes only accepts non-empty string arrays
What it means
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.
Source
Thrown at agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java:1409
Document specification = Document.parse(indexesJson);
if (isDefaultIdIndexSpecification(specification)) {
throw new IllegalArgumentException("The default MongoDB _id_ index cannot be dropped");
}
return specification;
}
if (value.isJsonArray()) {
if (single) {
throw new IllegalArgumentException("dropIndex only accepts a string index name or JSON document; arrays are not supported");
}
List<String> names = new ArrayList<>();
value.getAsJsonArray().forEach(item -> {
if (!item.isJsonPrimitive() || !item.getAsJsonPrimitive().isString() || item.getAsString().isBlank()) {
throw new IllegalArgumentException("dropIndexes only accepts arrays of string index names");
}
names.add(item.getAsString());
});
if (names.isEmpty()) {
throw new IllegalArgumentException("dropIndexes only accepts non-empty string arrays");
}
if (names.contains(DEFAULT_ID_INDEX_NAME)) {
throw new IllegalArgumentException("The default MongoDB _id_ index cannot be dropped");
}
return names;
}
if (single) {
throw new IllegalArgumentException("dropIndex only accepts a string index name or JSON document");
}
throw new IllegalArgumentException("dropIndexes only accepts a string index name, JSON document, or string array");
}
private static boolean isDefaultIdIndexSpecification(Document specification) {
if (specification.size() != 1 || !specification.containsKey("_id")) {
return false;
}
Object direction = specification.get("_id");
if (direction instanceof Number number) {View on GitHub (pinned to c0390bff16)
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
Example fix
// before
agent.dropIndexes(indexNamesJson); // may be "[]"
// after
if (!indexNames.isEmpty()) {
agent.dropIndexes(toJsonArray(indexNames));
} Defensive patterns
Strategy: validation
Validate before calling
if (Array.isArray(pendingNames) && pendingNames.length === 0) {
return { dropped: [] }; // no-op instead of calling dropIndexes([])
} Type guard
const isNonEmptyStringArray = (v) => Array.isArray(v) && v.length > 0;
Try / catch
try {
agent.dropIndexes(json);
} catch (IllegalArgumentException e) {
if (e.getMessage().includes("non-empty string arrays")) {
log.info('Nothing to drop; empty index list');
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- dropIndexes only accepts arrays of string index names
- dropIndexes only accepts a string index name, JSON document,
- runCommand requires a non-empty command document
- Index keys are required
- dropIndex only accepts a string index name or JSON document;
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/2487d76802ca22da.
Report an issue: GitHub.