{"id":"2e207ba7a5c97f87","repo":"apache/kafka","slug":"list-offsets-for-partition-partition-was-not-a","errorCode":null,"errorMessage":"List Offsets for partition \"{partition}\" was not attempted","messagePattern":"List Offsets for partition \"(.+?)\" was not attempted","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/admin/ListOffsetsResult.java","lineNumber":47,"sourceCode":"/**\n * The result of the {@link AdminClient#listOffsets(Map)} call.\n */\n@InterfaceAudience.Public\npublic class ListOffsetsResult {\n\n    private final Map<TopicPartition, KafkaFuture<ListOffsetsResultInfo>> futures;\n\n    public ListOffsetsResult(Map<TopicPartition, KafkaFuture<ListOffsetsResultInfo>> futures) {\n        this.futures = futures;\n    }\n\n    /**\n    * Return a future which can be used to check the result for a given partition.\n    */\n    public KafkaFuture<ListOffsetsResultInfo> partitionResult(final TopicPartition partition) {\n        KafkaFuture<ListOffsetsResultInfo> future = futures.get(partition);\n        if (future == null) {\n            throw new IllegalArgumentException(\n                    \"List Offsets for partition \\\"\" + partition + \"\\\" was not attempted\");\n        }\n        return future;\n    }\n\n    /**\n     * Return a future which succeeds only if offsets for all specified partitions have been successfully\n     * retrieved.\n     */\n    public KafkaFuture<Map<TopicPartition, ListOffsetsResultInfo>> all() {\n        return KafkaFuture.allOf(futures.values().toArray(new KafkaFuture<?>[0]))\n                .thenApply(v -> {\n                    Map<TopicPartition, ListOffsetsResultInfo> offsets = new HashMap<>(futures.size());\n                    for (Map.Entry<TopicPartition, KafkaFuture<ListOffsetsResultInfo>> entry : futures.entrySet()) {\n                        try {\n                            offsets.put(entry.getKey(), entry.getValue().get());\n                        } catch (InterruptedException | ExecutionException e) {\n                            // This should be unreachable, because allOf ensured that all the futures completed successfully.","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/admin/ListOffsetsResult.java#L29-L65","documentation":"Thrown by ListOffsetsResult.partitionResult(partition) when the given TopicPartition was not included in the original listOffsets request. The Admin client stores a future only for each requested partition; querying an unrequested partition is a client-side programming error.","triggerScenarios":"Calling result.partitionResult(tp) where tp was not a key in the Map<TopicPartition, OffsetSpec> passed to Admin.listOffsets. Common when the set of partitions iterated at result time differs from (or is a superset of) the set passed at request time.","commonSituations":"Listing offsets for partitions of a topic, then querying a partition that was added or renumbered between request and result handling; passing partitions discovered from metadata that includes partitions filtered out of the request; off-by-one partition index loops.","solutions":["Pass the exact same TopicPartition objects used in the listOffsets request when calling partitionResult","Build the request map once and iterate its keySet() when accessing per-partition results","Prefer the all() accessor when you need every requested partition's result"],"exampleFix":"// before\nMap<TopicPartition, OffsetSpec> req = new HashMap<>();\nreq.put(new TopicPartition(\"t\", 0), OffsetSpec.latest());\nListOffsetsResult r = admin.listOffsets(req);\nr.partitionResult(new TopicPartition(\"t\", 1)); // throws\n\n// after\nfor (TopicPartition tp : req.keySet()) {\n    r.partitionResult(tp).get();\n}","handlingStrategy":"validation","validationCode":"// Keep the set of TopicPartitions handed to listOffsets and check membership.\nSet<TopicPartition> requested = new HashSet<>(offsetSpecs.keySet());\nTopicPartition tp = ...;\nif (!requested.contains(tp)) {\n    // partition was not in the listOffsets request; skip or fix caller\n    return;\n}\nListOffsetsResult result = admin.listOffsets(offsetSpecs);\nresult.partitionResult(tp).get();","typeGuard":"static Optional<TopicPartition> requestedPartition(Set<TopicPartition> requested, TopicPartition tp) {\n    return tp != null && requested.contains(tp) ? Optional.of(tp) : Optional.empty();\n}","tryCatchPattern":"try {\n    result.partitionResult(tp).get();\n} catch (IllegalArgumentException e) {\n    // tp was not part of the listOffsets request map;\n    // reconcile the partition set the caller queries against the one it sent.\n    log.warn(\"Partition {} was not in the listOffsets request\", tp);\n}","preventionTips":["Derive every partitionResult() call from the same Map<TopicPartition, OffsetSpec> given to listOffsets.","Prefer result.all() when you want every requested partition instead of looping over an external collection.","Do not catch-and-retry; the partition is absent because it was never requested."],"tags":["kafka","admin-client","list-offsets","argument-mismatch"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}