t8y2/dbx · error · java.lang.IllegalArgumentException

Index name is required

Error message

Index name is required

What it means

When dropIndex receives a JSON string primitive as the index identifier, that string must be a non-blank index name. A whitespace/empty string cannot identify an index, so the agent throws immediately.

Source

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

        MongoClient c = requireClient();
        String database = params.get("database").getAsString();
        c.getDatabase(database).drop();
        return Collections.singletonMap("ok", true);
    }

    static Object parseDropIndexesValue(String indexesJson, boolean single) {
        if (indexesJson == null || indexesJson.isBlank()) {
            if (single) {
                throw new IllegalArgumentException("dropIndex requires a string index name or JSON document");
            }
            return "*";
        }

        JsonElement value = JsonParser.parseString(indexesJson);
        if (value.isJsonPrimitive() && value.getAsJsonPrimitive().isString()) {
            String name = value.getAsString();
            if (name.isBlank()) {
                throw new IllegalArgumentException("Index name is required");
            }
            if (single && "*".equals(name)) {
                throw new IllegalArgumentException("dropIndex does not accept \"*\"; use dropIndexes() or dropIndexes(\"*\") instead");
            }
            if (DEFAULT_ID_INDEX_NAME.equals(name)) {
                throw new IllegalArgumentException("The default MongoDB _id_ index cannot be dropped");
            }
            return name;
        }
        if (value.isJsonObject()) {
            JsonObject object = value.getAsJsonObject();
            if (object.size() == 0) {
                throw new IllegalArgumentException("Index specification is required");
            }
            Document specification = Document.parse(indexesJson);
            if (isDefaultIdIndexSpecification(specification)) {
                throw new IllegalArgumentException("The default MongoDB _id_ index cannot be dropped");
            }

View on GitHub (pinned to c0390bff16)

Solutions

  1. Supply the actual index name, e.g. "userId_1_createdAt_-1"
  2. Resolve the index name via listIndexes if unknown
  3. Add a caller-side blank check before invoking dropIndex

Example fix

// before
String index = env.get("DROP_INDEX"); // ""
agent.execute("dropIndex", Map.of("indexes", index));
// after
String index = env.get("DROP_INDEX");
if (index != null && !index.isBlank()) {
    agent.execute("dropIndex", Map.of("indexes", index));
}
Defensive patterns

Strategy: validation

Validate before calling

if (indexName == null || indexName.isBlank()) {
    throw new IllegalArgumentException("index name must be non-blank");
}
params.addProperty("indexes", indexName);

Type guard

boolean isValidIndexName(String name) {
    return name != null && !name.isBlank();
}

Try / catch

try {
    agent.execute("dropIndex", params);
} catch (IllegalArgumentException e) {
    if (e.getMessage().equals("Index name is required")) {
        log.error("Resolved index name was blank; check configuration source");
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling dropIndex with indexes="" (after parsing as a JSON string, e.g. '""' or a blank value), producing a blank name after JsonParser treats it as a string primitive.

Common situations: Empty environment variable or config field interpolated into the indexes parameter; trimming logic leaving whitespace; UI form submitted without the index name.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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