openzipkin/zipkin · error · NullPointerException

metrics == null

Error message

metrics == null

What it means

KafkaCollector.Builder.metrics is required: null throws NullPointerException. As with the ActiveMQ collector, the passed metrics are scoped to the 'kafka' transport via forTransport("kafka") before being delegated to the core Collector builder, so per-transport counters (messages, spans, bytes, drops) work.

Source

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

    CollectorMetrics metrics = CollectorMetrics.NOOP_METRICS;
    String topic = "zipkin";
    int streams = 1;

    @Override
    public Builder storage(StorageComponent storage) {
      delegate.storage(storage);
      return this;
    }

    @Override
    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");

View on GitHub (pinned to 878ce2a1fa)

Solutions

  1. Pass a real CollectorMetrics instance, minimally CollectorMetrics.NOOP_METRICS.
  2. Fix the DI binding or config lookup that yields null.
  3. Guard at the call site: metrics != null ? metrics : CollectorMetrics.NOOP_METRICS.

Example fix

// before
kafkaBuilder.metrics(resolveMetrics(cfg)); // returns null -> NPE

// after
CollectorMetrics m = resolveMetrics(cfg);
kafkaBuilder.metrics(m != null ? m : CollectorMetrics.NOOP_METRICS);
Defensive patterns

Strategy: validation

Validate before calling

java
CollectorMetrics m = (metrics != null) ? metrics : CollectorMetrics.NOOP_METRICS;
kafkaBuilder.metrics(m);

Prevention

When it happens

Trigger: Calling KafkaCollector.newBuilder(...).metrics(null) — typically DI wiring or config resolution producing null and being forwarded without a guard.

Common situations: Missing metrics binding in Guice/Spring; test bootstrap that skips metrics; a factory method returning null on invalid config and callers passing it through.

Related errors


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