openzipkin/zipkin · error · NullPointerException

topic == null

Error message

topic == null

What it means

KafkaCollector.Builder.topic(String) rejects null: the topic (or comma-delimited topic list) the collector consumes must be a concrete string. The default is "zipkin"; only an explicit null (not empty) is an error, mirroring the queue-name check in the ActiveMQ collector.

Source

Thrown at zipkin-collector/kafka/src/main/java/zipkin2/collector/kafka/KafkaCollector.java:85

    public Builder sampler(CollectorSampler sampler) {
      delegate.sampler(sampler);
      return this;
    }

    @Override
    public Builder metrics(CollectorMetrics metrics) {
      if (metrics == null) throw new NullPointerException("metrics == null");
      this.metrics = metrics.forTransport("kafka");
      delegate.metrics(this.metrics);
      return this;
    }

    /**
     * Topic zipkin spans will be consumed from. Defaults to "zipkin". Multiple topics may be
     * specified if comma delimited.
     */
    public Builder topic(String topic) {
      if (topic == null) throw new NullPointerException("topic == null");
      this.topic = topic;
      return this;
    }

    /** The bootstrapServers connect string, ex. 127.0.0.1:9092. No default. */
    public Builder bootstrapServers(String bootstrapServers) {
      if (bootstrapServers == null) throw new NullPointerException("bootstrapServers == null");
      properties.put(BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
      return this;
    }

    /** The consumer group this process is consuming on behalf of. Defaults to "zipkin" */
    public Builder groupId(String groupId) {
      if (groupId == null) throw new NullPointerException("groupId == null");
      properties.put(GROUP_ID_CONFIG, groupId);
      return this;
    }

View on GitHub (pinned to 878ce2a1fa)

Solutions

  1. Skip the .topic(...) call when unset to use the default "zipkin" topic.
  2. Or coalesce: .topic(t != null ? t : "zipkin").
  3. Verify the env/property name and that it is exported to the collector process.

Example fix

// before
String t = System.getenv("KAFKA_TOPIC"); // null when unset
builder.topic(t); // NPE

// after
if (System.getenv("KAFKA_TOPIC") != null) {
  builder.topic(System.getenv("KAFKA_TOPIC"));
}
Defensive patterns

Strategy: validation

Validate before calling

java
String t = System.getenv("KAFKA_TOPIC");
if (t != null) builder.topic(t); // defaults to "zipkin"

Prevention

When it happens

Trigger: Calling .topic(null), most commonly .topic(System.getenv("KAFKA_TOPIC")) or a properties lookup for an unset key.

Common situations: Optional topic override treated as mandatory; env var not exported in the deployment; property key typo (topics vs topic); test config omitting the topic.

Related errors


AI-assisted analysis of openzipkin/zipkin@878ce2a1fa (2026-08-14). Data as JSON: /api/errors/d6bc68c4e3722575. Report an issue: GitHub.