{"record":{"id":"a607f721d34a9d39","repo":"t8y2/dbx","slug":"name-must-be-a-non-negative-integer","errorCode":null,"errorMessage":"\" + name + \" must be a non-negative integer","messagePattern":"\" \\+ name \\+ \" must be a non-negative integer","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/kafka/src/main/java/com/dbx/agent/kafka/KafkaAgent.java","lineNumber":1549,"sourceCode":"            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;\n    }\n\n    private static long nonNegativeExactLong(JsonObject object, String name) {\n        JsonElement element = object.get(name);\n        if (element == null || !element.isJsonPrimitive() || !element.getAsJsonPrimitive().isNumber()) {\n            throw new IllegalArgumentException(name + \" must be a non-negative integer\");\n        }\n        try {\n            java.math.BigDecimal decimal = element.getAsBigDecimal();\n            if (decimal.signum() < 0 || decimal.stripTrailingZeros().scale() > 0) {\n                throw new IllegalArgumentException(name + \" must be a non-negative integer\");\n            }\n            return decimal.longValueExact();\n        } catch (ArithmeticException error) {\n            throw new IllegalArgumentException(name + \" is outside the supported integer range\", error);\n        }\n    }\n\n    static OffsetSpec offsetSpecForPosition(String position, Long timestampMs) {\n        String normalized = position == null ? \"latest\" : position.trim().toLowerCase(Locale.ROOT);\n        return switch (normalized) {\n            case \"earliest\" -> OffsetSpec.earliest();\n            case \"latest\", \"\" -> OffsetSpec.latest();\n            case \"timestamp\" -> {","sourceCodeStart":1531,"sourceCodeEnd":1567,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kafka/src/main/java/com/dbx/agent/kafka/KafkaAgent.java#L1531-L1567","documentation":"nonNegativeExactLong requires each numeric field (e.g. \"partition\", \"offset\") to be present, a JSON number primitive, non-negative, and integral. Missing fields, strings, booleans, negatives, or fractional numbers throw IllegalArgumentException \"<name> must be a non-negative integer\" (KafkaAgent.java:1549 and 1554).","triggerScenarios":"Omitting a required field; passing it as a string (\"42\" or \"abc\"); passing a negative value (-1); passing a decimal (1.5); passing null/boolean.","commonSituations":"Treating offsets as strings after JSON round-trips through a system that quotes numbers; using -1 or null as a sentinel for 'latest'; JavaScript number formatting producing floats.","solutions":["Send each field as a bare non-negative JSON integer, e.g. {\"partition\":0,\"offset\":100}","Unquote numeric values (remove surrounding quotes) in the payload","Replace sentinel values like -1/null with a proper position option (e.g. startPosition=latest) instead of an offset","Round or reject fractional values before sending"],"exampleFix":"// before\n{\"offsets\": [{\"partition\":\"0\",\"offset\":-1}]}\n// after\n{\"offsets\": [{\"partition\":0,\"offset\":100}]}","handlingStrategy":"validation","validationCode":"function checkNum(o){ for (const n of ['partition','offset']) { const v=o[n]; if (typeof v !== 'number' || !Number.isInteger(v) || v < 0) throw new Error(n+' must be a non-negative integer'); } }","typeGuard":"function isNonNegInt(v){ return typeof v === 'number' && Number.isInteger(v) && v >= 0; }","tryCatchPattern":"try { agent.execute(req); } catch (e) { if (String(e.message).includes('must be a non-negative integer')) { /* fix field type/value named in message */ } else throw e; }","preventionTips":["Send numbers as bare JSON integers, never strings","Avoid -1/null sentinels for offsets — use position options instead","Validate payloads with a schema before sending"],"tags":["kafka","input-validation","type-mismatch"],"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-14T05:17:10.506Z"}