Kafka Exception InvalidTopicException
org.apache.kafka.common.errors.InvalidTopicException
Non-retriable
Admin
The client has attempted to perform an operation on an invalid topic. For example the topic name is too long, contains invalid characters etc. This exception is not retriable because the operation won't suddenly become valid.
Common Causes
- Topic name contains invalid characters (spaces, special chars like '#', '\', '/' ) or exceeds the 249-character limit
- Topic name is '.' or '..' which are reserved and rejected by Kafka regardless of other settings
- Application dynamically constructing topic names from user input or config values that introduce illegal characters
Solutions
- Enforce topic naming conventions at the application layer: only allow [a-zA-Z0-9._-] characters, max 249 chars; add a validation function before any createTopic or produce call
- Use kafka-topics.sh --create with --if-not-exists and let the broker reject invalid names early in CI/CD pipelines rather than at runtime
- If topic names come from external systems, sanitize by replacing invalid chars with '-' or '_' and truncating to safe length before use
Example Stack Trace
org.apache.kafka.common.errors.InvalidTopicException: The request attempted to perform an operation on an invalid topic.Diagnostic Commands
# Describe topic partitions, leaders, and ISR
kafka-topics.sh --describe --topic '<topic>' --bootstrap-server localhost:9092
# List topics and search for the target topic
kafka-topics.sh --list --bootstrap-server localhost:9092 | grep -P '[^a-zA-Z0-9._-]'Related
Protocol error: INVALID_TOPIC_EXCEPTION (code 17)
Related Admin exceptions: InvalidConfigurationException · InvalidPartitionsException · InvalidReplicationFactorException · PolicyViolationException · ThrottlingQuotaExceededException · TopicExistsException · UnsupportedVersionException
Hitting
InvalidTopicException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.