{"record":{"id":"d27c8b3e3328da53","repo":"t8y2/dbx","slug":"offsets-must-contain-at-least-one-partition-offset","errorCode":null,"errorMessage":"offsets must contain at least one partition offset","messagePattern":"offsets must contain at least one partition offset","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/kafka/src/main/java/com/dbx/agent/kafka/KafkaAgent.java","lineNumber":1521,"sourceCode":"        }\n\n        admin.alterConsumerGroupOffsets(groupId, offsets)\n            .all().get(timeout, TimeUnit.MILLISECONDS);\n        return Collections.singletonMap(\"ok\", true);\n    }\n\n    static Map<TopicPartition, OffsetAndMetadata> explicitConsumerGroupOffsets(JsonObject params, String topic) {\n        Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>();\n        if (!params.has(\"offsets\")) {\n            return offsets;\n        }\n        JsonElement offsetsElement = params.get(\"offsets\");\n        if (!offsetsElement.isJsonArray()) {\n            throw new IllegalArgumentException(\"offsets must be an array\");\n        }\n        JsonArray offsetArray = offsetsElement.getAsJsonArray();\n        if (offsetArray.isEmpty()) {\n            throw new IllegalArgumentException(\"offsets must contain at least one partition offset\");\n        }\n        for (JsonElement element : offsetArray) {\n            if (!element.isJsonObject()) {\n                throw new IllegalArgumentException(\"each offset must be an object\");\n            }\n            JsonObject value = element.getAsJsonObject();\n            int partition = nonNegativeExactInt(value, \"partition\");\n            long offset = nonNegativeExactLong(value, \"offset\");\n            TopicPartition topicPartition = new TopicPartition(topic, partition);\n            if (offsets.put(topicPartition, new OffsetAndMetadata(offset)) != null) {\n                throw new IllegalArgumentException(\"duplicate partition in offsets: \" + partition);\n            }\n        }\n        return offsets;\n    }\n\n    private static int nonNegativeExactInt(JsonObject object, String name) {\n        long value = nonNegativeExactLong(object, name);","sourceCodeStart":1503,"sourceCodeEnd":1539,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kafka/src/main/java/com/dbx/agent/kafka/KafkaAgent.java#L1503-L1539","documentation":"KafkaAgent's commit-offsets request parsing rejects an \"offsets\" parameter that is an empty JSON array. Offsets must identify at least one (partition, offset) pair for the target topic, since committing nothing is a no-op the agent refuses to perform. Thrown as IllegalArgumentException from the offsets-parsing helper around KafkaAgent.java:1521.","triggerScenarios":"Calling the Kafka agent's offset-commit operation with params.offsets = [] (or an offsets field that serializes to an empty array).","commonSituations":"Building the offsets array programmatically from a filter/map that produced no results; a caller that always includes the offsets key even when there is nothing to commit.","solutions":["Populate offsets with at least one object containing non-negative integer \"partition\" and \"offset\" fields before calling","Skip the commit call entirely when the offsets list is empty instead of sending an empty array","Check that the JSON payload actually contains the offsets you built (e.g. log the request body)"],"exampleFix":"// before\nagent.execute(Map.of(\"op\",\"commitOffsets\",\"topic\",\"t\",\"offsets\",List.of()));\n// after\nList<Map<String,Object>> offsets = List.of(Map.of(\"partition\",0,\"offset\",42L));\nagent.execute(Map.of(\"op\",\"commitOffsets\",\"topic\",\"t\",\"offsets\",offsets));","handlingStrategy":"validation","validationCode":"if (!Array.isArray(offsets) || offsets.length === 0) throw new Error('offsets must contain at least one entry');","typeGuard":"function hasOffsets(o) { return Array.isArray(o) && o.length > 0; }","tryCatchPattern":"try { agent.execute(req); } catch (e) { if (e instanceof IllegalArgumentException && e.getMessage().contains('offsets must contain')) { /* fix payload */ } else throw e; }","preventionTips":["Never send an offsets array you have not verified is non-empty","Skip the commit call when there is nothing to commit","Log the outgoing payload when building offsets dynamically"],"tags":["kafka","input-validation","offsets"],"backgroundTag":"empty-collection-argument","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"}