quarkusio/quarkus · error · IllegalArgumentException
Topic doesn't exist:
Error message
Topic doesn't exist:
What it means
Thrown by KafkaAdminManager.partitions after a describeTopics call returns no description for the requested topic. The admin client succeeded (no execution error) but Kafka reports the topic as absent, so the manager rejects the lookup with IllegalArgumentException.
Source
Thrown at integration-tests/compose-devservices/src/main/java/io/quarkus/it/compose/devservices/kafka/KafkaAdminManager.java:67
admin.createTopics(List.of(new NewTopic(topic, partitions, (short) 1))).all()
.get(2000, TimeUnit.MILLISECONDS);
}
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}
}
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();
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Verify the topic name matches exactly (case-sensitive) what exists: kafka-topics --bootstrap-server ... --list.
- Enable auto-topic creation or create the topic explicitly before calling partitions().
- Check that the app/Dev Services connect to the same broker as the compose service (correct bootstrap servers / port mapping).
Example fix
// before
int p = manager.partitions("mytopic"); // topic never created
// after
admin.createTopics(List.of(new NewTopic("mytopic", 1, (short) 1))).all().get();
int p = manager.partitions("mytopic"); Defensive patterns
Strategy: retry
Validate before calling
Set<String> topics = admin.listTopics().names().get(5, TimeUnit.SECONDS);
if (!topics.contains(topic)) {
admin.createTopics(List.of(new NewTopic(topic, 1, (short) 1))).all().get();
} Type guard
boolean topicExists(KafkaAdmin admin, String name) throws Exception {
return admin.listTopics().names().get(5, TimeUnit.SECONDS).contains(name);
} Try / catch
try {
int partitions = manager.partitions(topic);
} catch (IllegalArgumentException e) {
log.warn("Topic missing, creating it and retrying: " + topic);
createTopicAndWait(topic);
} Prevention
- Create topics explicitly before consuming their metadata.
- Enable auto.create.topics.enable in dev brokers.
- Wait for Kafka container readiness before tests touch topics.
- Confirm bootstrap servers point at the same broker that holds the topic.
When it happens
Trigger: Calling partitions(topic) where the topic name is misspelled, the topic was deleted, or the Kafka broker (often started via compose/Dev Services) has not yet created/auto-created the topic.
Common situations: Dev Services Kafka started from docker-compose with auto-create disabled; race where the producer has not yet created the topic; connecting to the wrong broker/cluster than the one holding the topic; compose service not exposing the expected port.
Related errors
- The fixed Kafka port must be greater than 0
- Topic doesn't exist: " + topic
- Services have not been started yet
- Services named ${servicesToWaitFor} do not exist, but wait c
- Docker Compose not found. Is ${composeExecutable} on the PAT
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/8522682d0f64e1ea.
Report an issue: GitHub.