openzipkin/zipkin · error · NullPointerException

metrics == null

Error message

metrics == null

What it means

Collector.Builder.metrics throws NullPointerException on null. Metrics count messages, spans, bytes, and drops per transport; although the Collector constructor would silently default to CollectorMetrics.NOOP_METRICS if unset, explicitly passing null is treated as a bug and rejected at the setter.

Source

Thrown at zipkin-collector/core/src/main/java/zipkin2/collector/Collector.java:66

    final Logger logger;
    StorageComponent storage;
    CollectorSampler sampler;
    CollectorMetrics metrics;

    Builder(Logger logger) {
      this.logger = logger;
    }

    /** Sets {@link {@link CollectorComponent.Builder#storage(StorageComponent)}} */
    public Builder storage(StorageComponent storage) {
      if (storage == null) throw new NullPointerException("storage == null");
      this.storage = storage;
      return this;
    }

    /** Sets {@link {@link CollectorComponent.Builder#metrics(CollectorMetrics)}} */
    public Builder metrics(CollectorMetrics metrics) {
      if (metrics == null) throw new NullPointerException("metrics == null");
      this.metrics = metrics;
      return this;
    }

    /** Sets {@link {@link CollectorComponent.Builder#sampler(CollectorSampler)}} */
    public Builder sampler(CollectorSampler sampler) {
      if (sampler == null) throw new NullPointerException("sampler == null");
      this.sampler = sampler;
      return this;
    }

    public Collector build() {
      return new Collector(this);
    }
  }

  final Logger logger;
  final CollectorMetrics metrics;

View on GitHub (pinned to 878ce2a1fa)

Solutions

  1. Pass a concrete CollectorMetrics such as InMemoryCollectorMetrics (exposed in the server) or NOOP_METRICS.
  2. Default before passing: metrics != null ? metrics : CollectorMetrics.NOOP_METRICS.
  3. Fix the DI binding so a metrics implementation is always available.

Example fix

// before
builder.metrics(context.getBean(CollectorMetrics.class)); // null bean -> NPE

// after
CollectorMetrics m = context.getBean(CollectorMetrics.class);
builder.metrics(m != null ? m : CollectorMetrics.NOOP_METRICS);
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: Calling .metrics(null) — e.g. a metrics bean absent from DI context and passed through unconditionally.

Common situations: Guice/Spring module where the CollectorMetrics binding is missing; optional metrics config resolved to null; test wiring copied without the metrics line.

Related errors


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