{"id":"5afa3b32ff2340ed","repo":"apache/kafka","slug":"topic-partition-partition-was-not-included-in-th","errorCode":null,"errorMessage":"Topic partition {partition} was not included in the request","messagePattern":"Topic partition (.+?) was not included in the request","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"clients/src/main/java/org/apache/kafka/clients/admin/DescribeProducersResult.java","lineNumber":42,"sourceCode":"\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.concurrent.ExecutionException;\n\n@InterfaceAudience.Public\npublic class DescribeProducersResult {\n\n    private final Map<TopicPartition, KafkaFuture<PartitionProducerState>> futures;\n\n    DescribeProducersResult(Map<TopicPartition, KafkaFuture<PartitionProducerState>> futures) {\n        this.futures = futures;\n    }\n\n    public KafkaFuture<PartitionProducerState> partitionResult(final TopicPartition partition) {\n        KafkaFuture<PartitionProducerState> future = futures.get(partition);\n        if (future == null) {\n            throw new IllegalArgumentException(\"Topic partition \" + partition +\n                \" was not included in the request\");\n        }\n        return future;\n    }\n\n    public KafkaFuture<Map<TopicPartition, PartitionProducerState>> all() {\n        return KafkaFuture.allOf(futures.values().toArray(new KafkaFuture<?>[0]))\n            .thenApply(nil -> {\n                Map<TopicPartition, PartitionProducerState> results = new HashMap<>(futures.size());\n                for (Map.Entry<TopicPartition, KafkaFuture<PartitionProducerState>> entry : futures.entrySet()) {\n                    try {\n                        results.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.\n                        throw new KafkaException(e);\n                    }\n                }\n                return results;","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/admin/DescribeProducersResult.java#L24-L60","documentation":"Thrown by DescribeProducersResult.partitionResult when the caller asks for the producer state of a TopicPartition that was not part of the original Admin.describeProducers request. The result holds a future per requested partition; a missing key means the partition was not requested and is a programming error (IllegalArgumentException).","triggerScenarios":"Calling result.partitionResult(tp) with a TopicPartition not present in the DescribeProducersOptions partitions (or the request set) passed to Admin.describeProducers. Common when partition numbering differs between request and lookup, or the caller reuses the result for partitions not originally described.","commonSituations":"Building the describe request from metadata while the lookup uses hardcoded partition numbers; off-by-one partition index; topic renamed between request and lookup; multi-tenant code that shares a result object across callers requesting different partitions.","solutions":["Look up only TopicPartition values that you passed to Admin.describeProducers.","Iterate the original partition set returned by the request rather than constructing new keys.","If you need state for an additional partition, issue a new describeProducers call.","Confirm topic name and partition index match the request exactly."],"exampleFix":"// before\nSet<TopicPartition> req = Set.of(new TopicPartition(\"orders\", 0));\nDescribeProducersResult r = admin.describeProducers(req).all().get()...;\nr.partitionResult(new TopicPartition(\"orders\", 2)); // not in request\n\n// after\nfor (TopicPartition tp : req) {\n    r.partitionResult(tp);\n}","handlingStrategy":"validation","validationCode":"// Keep the collection of TopicPartitions sent to describeProducers and look up\n// only those via partitionResult(...).\nList<TopicPartition> requested = List.of(\n    new TopicPartition(\"orders\", 0),\n    new TopicPartition(\"orders\", 1));\nDescribeProducersResult result = admin.describeProducers(requested);\n\nfor (TopicPartition tp : requested) {\n    // guaranteed present; no IllegalArgumentException\n    PartitionProducerState state = result.partitionResult(tp).get();\n    ...\n}","typeGuard":null,"tryCatchPattern":"try {\n    PartitionProducerState s = result.partitionResult(tp).get();\n} catch (IllegalArgumentException e) {\n    // `tp` was not in the describeProducers request. Resubmit or drop.\n    log.warn(\"Partition {} not described: {}\", tp, e.getMessage());\n}","preventionTips":["Drive every partitionResult(...) call from the same collection passed to Admin.describeProducers.","Use result.all() when you want the full map and do not need selective lookups.","Avoid deriving TopicPartition objects from offsets/metadata in a separate code path; reuse the request list.","If partitions are added dynamically, issue a new describeProducers request rather than querying the stale result."],"tags":["admin-client","producer-state","api-misuse","illegal-argument","request-set"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}