quarkusio/quarkus · error · IllegalArgumentException
Topic doesn't exist: " + topic
Error message
Topic doesn't exist: " + topic
What it means
KafkaAdminManager.partitions() describes a Kafka topic via AdminClient.describeTopics and throws IllegalArgumentException('Topic doesn't exist: <topic>') when the returned map contains no entry for the requested topic name. Note describeTopics can also surface unknown-topic errors as ExecutionException; this branch handles the case where the call succeeded but the topic was absent from the result map. It indicates a mismatch between the topic name requested and the topics that exist on the broker.
Source
Thrown at integration-tests/kafka-devservices/src/main/java/io/quarkus/it/kafka/KafkaAdminManager.java:54
}
@PreDestroy
void cleanup() {
admin.close();
}
public int partitions(String topic) {
TopicDescription topicDescription;
try {
Map<String, TopicDescription> partitions = admin.describeTopics(Collections.singletonList(topic))
.allTopicNames().get(2000, TimeUnit.MILLISECONDS);
topicDescription = partitions.get(topic);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}
if (topicDescription == null) {
throw new IllegalArgumentException("Topic doesn't exist: " + topic);
}
return topicDescription.partitions().size();
}
int port() throws InterruptedException, ExecutionException {
return admin.describeCluster().controller().get().port();
}
String image() throws InterruptedException, ExecutionException {
// By observation, the red panda does not return anything for the supported features call
// It would be nice to have a more robust check, but hopefully this fragile check is good enough
boolean isRedPanda = admin.describeFeatures().featureMetadata().get().supportedFeatures().size() == 0;
return isRedPanda ? "redpanda" : "kafka-native";
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Create the topic before calling partitions (via AdminClient.createTopics or Kafka Connect/newTopic @Produces beans)
- Check the topic name spelling/case against admin.listTopics() output
- Verify kafka.bootstrap.servers points to the broker/Dev Service instance where the topic actually exists
- Increase wait/retry if Dev Services has not finished creating topics before the call (the 2000ms timeout is tight)
Example fix
// before
if (topicDescription == null) {
throw new IllegalArgumentException("Topic doesn't exist: " + topic);
}
// after
if (topicDescription == null) {
admin.createTopics(Collections.singletonList(new NewTopic(topic, 1, (short) 1))).all().get();
topicDescription = admin.describeTopics(Collections.singletonList(topic)).allTopicNames().get(topic);
} Defensive patterns
Strategy: validation
Validate before calling
Set<String> existing = admin.listTopics().names().get(5, TimeUnit.SECONDS);
if (!existing.contains(topic)) {
throw new IllegalStateException("Topic not present before describe: " + topic
+ "; existing=" + existing);
} Try / catch
try {
int partitions = kafkaAdminManager.partitions(topic);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Topic doesn't exist:")) {
// create the topic or correct the configured topic name, then retry once
} else {
throw e;
}
} Prevention
- Create all needed topics at startup (NewTopic beans / AdminClient.createTopics) before describing them
- Compare configured topic names against admin.listTopics() in a startup health check
- Watch for case/whitespace differences in topic names from config properties
- Allow time for Dev Services topic auto-creation before querying; the 2000ms timeout in partitions() is aggressive
When it happens
Trigger: Calling partitions("some-topic") when the topic was never created, was deleted, or the name is misspelled/case-mismatched — e.g. Dev Services for Kafka has not yet created the topic, or the configured kafka.topic name differs from the created topic.
Common situations: Dev Services environment where topic auto-creation hasn't run yet or the broker (redpanda/kafka-native) reset state; tests pointing at a different bootstrap server than where the topic exists; typos in topic names passed via config.
Related errors
- The fixed Kafka port must be greater than 0
- Topic doesn't exist:
- Name cannot start with '/':${name}
- Predicate already set
- Location already set
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/a5d9c797cafc5678.
Report an issue: GitHub.