t8y2/dbx · error · java.lang.IllegalArgumentException

dropIndexes only accepts a string index name, JSON document,

Error message

dropIndexes only accepts a string index name, JSON document, or string array

What it means

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.

Source

Thrown at agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java:1419

            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) {
            return number.doubleValue() == 1.0;
        }
        // Document.parse turns Extended JSON $numberDecimal values into
        // Decimal128, which does not implement Number in the legacy driver.
        return direction instanceof Decimal128 decimal
            && decimal.bigDecimalValue().compareTo(BigDecimal.ONE) == 0;
    }

    private static List<IndexInfo> listIndexInfos(MongoClient c, String database, String collection) {
        List<IndexInfo> result = new ArrayList<>();

View on GitHub (pinned to c0390bff16)

Solutions

  1. Pass a JSON array of string names: dropIndexes("[\"idx_a\",\"idx_b\"]")
  2. Or a single string name, or an object specification, depending on the intent
  3. Validate the argument parses to a string/object/array before invoking the tool

Example fix

// before
agent.dropIndexes("42");
// after
agent.dropIndexes("[\"email_idx\", \"age_1\"]");
Defensive patterns

Strategy: type-guard

Validate before calling

const okShape = (v) => typeof v === 'string' ||
  (Array.isArray(v) && v.every(x => typeof x === 'string')) ||
  (v !== null && typeof v === 'object' && !Array.isArray(v));
if (!okShape(arg)) throw new Error('dropIndexes arg must be a string name, object spec, or string array');

Type guard

const isDropIndexesShape = (v) =>
  typeof v === 'string' ||
  (Array.isArray(v) && v.every(x => typeof x === 'string')) ||
  (v !== null && typeof v === 'object' && !Array.isArray(v));

Try / catch

try {
  agent.dropIndexes(arg);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("dropIndexes only accepts a string index name")) {
    log.error('dropIndexes got unsupported JSON type', { arg });
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/dbbdd75ce3090b45. Report an issue: GitHub.