apache/kafka · warning · IllegalArgumentException
Topic partition {partition} was not included in the request
Error message
Topic partition {partition} was not included in the request What it means
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).
Source
Thrown at clients/src/main/java/org/apache/kafka/clients/admin/DescribeProducersResult.java:42
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@InterfaceAudience.Public
public class DescribeProducersResult {
private final Map<TopicPartition, KafkaFuture<PartitionProducerState>> futures;
DescribeProducersResult(Map<TopicPartition, KafkaFuture<PartitionProducerState>> futures) {
this.futures = futures;
}
public KafkaFuture<PartitionProducerState> partitionResult(final TopicPartition partition) {
KafkaFuture<PartitionProducerState> future = futures.get(partition);
if (future == null) {
throw new IllegalArgumentException("Topic partition " + partition +
" was not included in the request");
}
return future;
}
public KafkaFuture<Map<TopicPartition, PartitionProducerState>> all() {
return KafkaFuture.allOf(futures.values().toArray(new KafkaFuture<?>[0]))
.thenApply(nil -> {
Map<TopicPartition, PartitionProducerState> results = new HashMap<>(futures.size());
for (Map.Entry<TopicPartition, KafkaFuture<PartitionProducerState>> entry : futures.entrySet()) {
try {
results.put(entry.getKey(), entry.getValue().get());
} catch (InterruptedException | ExecutionException e) {
// This should be unreachable, because allOf ensured that all the futures completed successfully.
throw new KafkaException(e);
}
}
return results;View on GitHub (pinned to c31c9215e1)
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.
Example fix
// before
Set<TopicPartition> req = Set.of(new TopicPartition("orders", 0));
DescribeProducersResult r = admin.describeProducers(req).all().get()...;
r.partitionResult(new TopicPartition("orders", 2)); // not in request
// after
for (TopicPartition tp : req) {
r.partitionResult(tp);
} Defensive patterns
Strategy: validation
Validate before calling
// Keep the collection of TopicPartitions sent to describeProducers and look up
// only those via partitionResult(...).
List<TopicPartition> requested = List.of(
new TopicPartition("orders", 0),
new TopicPartition("orders", 1));
DescribeProducersResult result = admin.describeProducers(requested);
for (TopicPartition tp : requested) {
// guaranteed present; no IllegalArgumentException
PartitionProducerState state = result.partitionResult(tp).get();
...
} Try / catch
try {
PartitionProducerState s = result.partitionResult(tp).get();
} catch (IllegalArgumentException e) {
// `tp` was not in the describeProducers request. Resubmit or drop.
log.warn("Partition {} not described: {}", tp, e.getMessage());
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Partition {partition} was not included in the original reque
- Topic {topic} was not included in the original request
- TransactionalId `{transactionalId}` was not included in the
- TransactionalId `{transactionalId}` was not included in the
- Cannot specify a negative version level.
AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03).
Data as JSON: /data/errors/5afa3b32ff2340ed.json.
Report an issue: GitHub.