{"record":{"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/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/admin/ListOffsetsResult.java#L29-L65","documentation":"An IllegalArgumentException thrown by ListOffsetsResult.partitionResult(TopicPartition) when the given partition was not part of the original listOffsets request. The result only contains futures for partitions you asked about; any other partition is a caller bug.","triggerScenarios":"Calling Admin.listOffsets(Map<TopicPartition, ...>) with a set of partitions, then calling result.partitionResult(tp) for a TopicPartition that was not a key in that map. Constructing a TopicPartition with a different topic name or partition number than requested.","commonSituations":"Iterating a different (larger) partition set when reading results than was used for the request; off-by-one in partition numbering; race conditions where the requested map is mutated between request and result handling.","solutions":["Iterate the exact keyset of the Map passed to listOffsets when calling partitionResult.","Cache the requested Map<TopicPartition, OffsetSpec> and reuse its keys for result access.","Use result.all() when you do not need per-partition accessor semantics."],"exampleFix":"// before\nMap<TopicPartition, OffsetSpec> req = ...;\nListOffsetsResult r = admin.listOffsets(req);\nr.partitionResult(new TopicPartition(\"otherTopic\", 0));\n\n// after\nfor (TopicPartition tp : req.keySet()) {\n    r.partitionResult(tp);\n}","handlingStrategy":"validation","validationCode":"Map<TopicPartition, OffsetSpec> request = ...;\nListOffsetsResult r = admin.listOffsets(request);\nfor (TopicPartition tp : request.keySet()) r.partitionResult(tp);","typeGuard":"static boolean wasRequested(TopicPartition tp, Set<TopicPartition> requested) {\n    return requested.contains(tp);\n}","tryCatchPattern":null,"preventionTips":["Cache the request map and iterate its keyset for result access.","Use result.all() when per-partition access is not required."],"tags":["kafka-admin","offsets","argument-validation","client-side"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}