{"record":{"id":"dc273891b8149613","repo":"t8y2/dbx","slug":"peek-message-count-must-be-between-1-and-max-p","errorCode":null,"errorMessage":"Peek message count must be between 1 and \" + MAX_PEEK_MESSAGE_COUNT","messagePattern":"Peek message count must be between 1 and \" \\+ MAX_PEEK_MESSAGE_COUNT","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"agents/drivers/kafka/src/main/java/com/dbx/agent/kafka/KafkaAgent.java","lineNumber":1708,"sourceCode":"                );\n            }\n            List<Map<String, Object>> messages = sortAndLimitPeekedMessages(\n                collection.messages, count, startPosition\n            );\n            return peekMessagesResult(messages, collection.incomplete);\n        }\n    }\n\n    static Map<String, Object> peekMessagesResult(List<Map<String, Object>> messages, boolean incomplete) {\n        Map<String, Object> result = new LinkedHashMap<>();\n        result.put(\"messages\", messages);\n        result.put(\"incomplete\", incomplete);\n        return result;\n    }\n\n    static int validatedPeekCount(int count) {\n        if (count < 1 || count > MAX_PEEK_MESSAGE_COUNT) {\n            throw new IllegalArgumentException(\n                \"Peek message count must be between 1 and \" + MAX_PEEK_MESSAGE_COUNT\n            );\n        }\n        return count;\n    }\n\n    static int peekRequestTimeoutMs(JsonObject conn, Properties props) {\n        Integer connectionTimeout = integerOrNull(conn, \"request_timeout_ms\");\n        if (connectionTimeout != null) {\n            return positiveTimeoutMs(\"request_timeout_ms\", connectionTimeout);\n        }\n        String configuredTimeout = props.getProperty(\n            ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG,\n            String.valueOf(DEFAULT_REQUEST_TIMEOUT_MS)\n        );\n        try {\n            return positiveTimeoutMs(ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG, Integer.parseInt(configuredTimeout));\n        } catch (NumberFormatException error) {","sourceCodeStart":1690,"sourceCodeEnd":1726,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kafka/src/main/java/com/dbx/agent/kafka/KafkaAgent.java#L1690-L1726","documentation":"KafkaAgent.validatePeekCount enforces that the `count` parameter of a peek operation is between 1 and MAX_PEEK_MESSAGE_COUNT. The library throws this IllegalArgumentException before creating a consumer to fail fast on out-of-range peek sizes. It protects the driver from building enormous fetch requests or returning unbounded result sets.","triggerScenarios":"Calling the Kafka peek API with count < 1 (e.g. 0 or negative) or count > MAX_PEEK_MESSAGE_COUNT. validatedPeekCount is invoked on every peek request that specifies a message count.","commonSituations":"Defaulting a UI page size to 0 before the user picks a value; passing a raw user input string parsed to 0; copying a 'limit' of 0 from another connector; requesting tens of thousands of messages to 'drain' a topic.","solutions":["Clamp the requested count into the range [1, MAX_PEEK_MESSAGE_COUNT] before calling the peek API.","Default to a small sane value (e.g. 10) when the caller supplies 0/null.","Catch IllegalArgumentException and surface a validation message to the user prompting a value in range."],"exampleFix":"// before\nagent.peek(conn, topic, count /* count = 0 */);\n\n// after\nint safeCount = Math.max(1, Math.min(count, MAX_PEEK_MESSAGE_COUNT));\nagent.peek(conn, topic, safeCount);","handlingStrategy":"validation","validationCode":"int MAX_PEEK_MESSAGE_COUNT = 100; // match driver constant\nif (count < 1 || count > MAX_PEEK_MESSAGE_COUNT) {\n    throw new IllegalArgumentException(\"count must be in [1, \" + MAX_PEEK_MESSAGE_COUNT + \"]\");\n}","typeGuard":"boolean isValidPeekCount(int count) { return count >= 1 && count <= 100; }","tryCatchPattern":"try {\n    result = agent.peek(conn, topic, count);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Peek message count\")) {\n        result = agent.peek(conn, topic, 10); // safe default\n    } else throw e;\n}","preventionTips":["Clamp user-supplied page sizes to [1, MAX_PEEK_MESSAGE_COUNT] at the UI/API boundary","Default null/0 counts to a small sane value before calling peek","Share the driver's MAX_PEEK_MESSAGE_COUNT constant in client validation"],"tags":["kafka","validation","argument-validation"],"backgroundTag":"parameter-out-of-range","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"}