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

  1. Create the topic before calling partitions (via AdminClient.createTopics or Kafka Connect/newTopic @Produces beans)
  2. Check the topic name spelling/case against admin.listTopics() output
  3. Verify kafka.bootstrap.servers points to the broker/Dev Service instance where the topic actually exists
  4. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/a5d9c797cafc5678. Report an issue: GitHub.