{"record":{"id":"0709700d1eef1e49","repo":"t8y2/dbx","slug":"each-offset-must-be-an-object","errorCode":null,"errorMessage":"each offset must be an object","messagePattern":"each offset must be an object","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/kafka/src/main/java/com/dbx/agent/kafka/KafkaAgent.java","lineNumber":1525,"sourceCode":"        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);\n        if (value > Integer.MAX_VALUE) {\n            throw new IllegalArgumentException(name + \" is outside the supported integer range\");\n        }\n        return (int) value;","sourceCodeStart":1507,"sourceCodeEnd":1543,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kafka/src/main/java/com/dbx/agent/kafka/KafkaAgent.java#L1507-L1543","documentation":"Each element of the \"offsets\" array must be a JSON object describing one partition offset. The parser iterates the array and throws IllegalArgumentException as soon as an element is not an object (KafkaAgent.java:1525).","triggerScenarios":"Passing offsets like [1], [\"0\"], [null], or [[0,100]] where array items are numbers/strings/nulls/nested arrays instead of objects with partition/offset fields.","commonSituations":"Hand-written JSON payloads missing braces; serializing a Map.Entry or tuple directly instead of a structured object; double-encoding offsets as strings.","solutions":["Wrap each offset entry as an object: {\"partition\": <int>, \"offset\": <long>}","Verify the JSON serialization step is not flattening objects into scalars","Validate the array client-side before sending (every element is a JSON object)"],"exampleFix":"// before\n{\"offsets\": [0, 1]}\n// after\n{\"offsets\": [{\"partition\": 0, \"offset\": 100}, {\"partition\": 1, \"offset\": 200}]}","handlingStrategy":"validation","validationCode":"const ok = Array.isArray(offsets) && offsets.every(o => o !== null && typeof o === 'object' && !Array.isArray(o));","typeGuard":"function isOffsetEntry(o) { return typeof o === 'object' && o !== null && !Array.isArray(o) && Number.isInteger(o.partition) && Number.isInteger(o.offset) && o.partition >= 0 && o.offset >= 0; }","tryCatchPattern":"try { agent.execute(req); } catch (e) { if (String(e.message).includes('each offset must be an object')) { /* inspect offsets elements */ } else throw e; }","preventionTips":["Always serialize offsets as objects with partition and offset keys","Validate each element shape before sending","Avoid passing raw tuples or scalars as offsets"],"tags":["kafka","input-validation","json-shape"],"backgroundTag":"schema-validation-failed","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"}