openzipkin/zipkin · error · NullPointerException

bootstrapServers == null

Error message

bootstrapServers == null

What it means

KafkaCollector.Builder.bootstrapServers(String) rejects a null argument with NullPointerException. bootstrapServers is the Kafka connect string (e.g. 127.0.0.1:9092) and has no default, so the builder enforces that you supply one before build(). This is a fail-fast guard in the builder, thrown at configuration time, not at connection time.

Source

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

      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;
    }

    /** Count of threads consuming the topic. Defaults to 1 */
    public Builder streams(int streams) {
      this.streams = streams;
      return this;
    }

    /**

View on GitHub (pinned to 878ce2a1fa)

Solutions

  1. Set the bootstrapServers value explicitly, e.g. .bootstrapServers("127.0.0.1:9092") or from environment: .bootstrapServers(System.getenv("KAFKA_BOOTSTRAP_SERVERS"))
  2. If the value comes from config, validate/require it at application startup before building the collector
  3. For tests, point it at an embedded Kafka broker or a Testcontainers Kafka instance

Example fix

// before
KafkaCollector collector = KafkaCollector.newBuilder()
  .bootstrapServers(System.getenv("KAFKA_BOOTSTRAP_SERVERS")) // null in this env
  .build();

// after
String bootstrap = requireNonNull(
  System.getenv("KAFKA_BOOTSTRAP_SERVERS"), "KAFKA_BOOTSTRAP_SERVERS must be set");
KafkaCollector collector = KafkaCollector.newBuilder()
  .bootstrapServers(bootstrap)
  .build();
Defensive patterns

Strategy: validation

Validate before calling

String bootstrap = System.getenv("KAFKA_BOOTSTRAP_SERVERS");
if (bootstrap == null || bootstrap.isEmpty()) {
  throw new IllegalStateException("KAFKA_BOOTSTRAP_SERVERS is required");
}
KafkaCollector.newBuilder().bootstrapServers(bootstrap);

Prevention

When it happens

Trigger: Calling KafkaCollector.newBuilder().bootstrapServers(null), or passing a variable that is null (e.g. an unset environment variable or system property parsed to null) into bootstrapServers().

Common situations: Reading KAFKA_BOOTSTRAP_SERVERS from config/env that is missing in a deployment (e.g. Docker/Kubernetes), or wiring the collector in a test without setting the Kafka address. Because there is no default, any deployment that forgets the Kafka connect string fails here.

Related errors


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