openzipkin/zipkin · error · NullPointerException

storage == null

Error message

storage == null

What it means

Collector.Builder.storage rejects null because a Collector is meaningless without a StorageComponent to accept spans into. Storage is the one required dependency with no NOOP default — the Collector constructor re-checks it — so fail-fast at the setter keeps the error at the call site.

Source

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

  /** Needed to scope this to the correct logging category */
  public static Builder newBuilder(Class<?> loggingClass) {
    if (loggingClass == null) throw new NullPointerException("loggingClass == null");
    return new Builder(LoggerFactory.getLogger(loggingClass.getName()));
  }

  public static final class Builder {
    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;
    }

View on GitHub (pinned to 878ce2a1fa)

Solutions

  1. Construct and pass a real StorageComponent first (e.g. MySQLStorage.newBuilder(...)....build()).
  2. For tests, use an in-memory storage: StorageComponent InMemoryStorage.newBuilder().build().
  3. Fix the wiring so storage is guaranteed non-null before the collector is built.

Example fix

// before
StorageComponent s = config.storage(); // null when config missing
Collector.newBuilder(cls).storage(s); // NPE

// after
StorageComponent s = requireNonNull(config.storage(), "storage config missing");
Collector.newBuilder(cls).storage(s);
Defensive patterns

Strategy: validation

Validate before calling

java
StorageComponent storage = Objects.requireNonNull(config.storage(), "storage config missing");
Collector.newBuilder(cls).storage(storage);

Prevention

When it happens

Trigger: Calling .storage(null) on the Collector builder, typically when the storage component construction (e.g. MySQL/ES storage from config) failed or was skipped and null is forwarded.

Common situations: Storage config block missing or mis-typed so the factory returns null; conditional storage setup skipped on a code path; tests building a Collector without a storage double.

Related errors


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