openzipkin/zipkin · error · NullPointerException

datasource == null

Error message

datasource == null

What it means

MySQLStorage.Builder.datasource throws NullPointerException when the DataSource argument is null. The DataSource is the single mandatory dependency of the MySQL storage: every query goes through jOOQ over this connection pool. The builder rejects null immediately so the failure happens at configuration time rather than at first query.

Source

Thrown at zipkin-storage/mysql-v1/src/main/java/zipkin2/storage/mysql/v1/MySQLStorage.java:59

    @Override public Builder strictTraceId(boolean strictTraceId) {
      this.strictTraceId = strictTraceId;
      return this;
    }

    @Override public Builder searchEnabled(boolean searchEnabled) {
      this.searchEnabled = searchEnabled;
      return this;
    }

    @Override public Builder autocompleteKeys(List<String> keys) {
      if (keys == null) throw new NullPointerException("keys == null");
      this.autocompleteKeys = keys;
      return this;
    }

    public Builder datasource(DataSource datasource) {
      if (datasource == null) throw new NullPointerException("datasource == null");
      this.datasource = datasource;
      return this;
    }

    public Builder settings(Settings settings) {
      if (settings == null) throw new NullPointerException("settings == null");
      this.settings = settings;
      return this;
    }

    public Builder listenerProvider(@Nullable ExecuteListenerProvider listenerProvider) {
      this.listenerProvider = listenerProvider;
      return this;
    }

    public Builder executor(Executor executor) {
      if (executor == null) throw new NullPointerException("executor == null");
      this.executor = executor;

View on GitHub (pinned to 878ce2a1fa)

Solutions

  1. Supply a live javax.sql.DataSource (HikariDataSource, MysqlDataSource, etc.) before build().
  2. If using DI, verify the DataSource bean exists in the active profile and is injected before the storage bean is constructed.
  3. For tests, point a HikariDataSource at a MySQL container (e.g. Testcontainers) instead of leaving the field null.

Example fix

// before
MySQLStorage storage = builder.build(); // datasource never set -> NPE later at line 102 only if datasource(null) called
builder.datasource(null);

// after
HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl("jdbc:mysql://localhost:3306/zipkin");
builder.datasource(ds);
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(dataSource, "dataSource must be configured before building MySQLStorage");
builder.datasource(dataSource);

Prevention

When it happens

Trigger: Calling builder.datasource(null), e.g. wiring a DataSource bean that failed to be created or a DI field that is still null at builder time.

Common situations: Spring/Boot wiring where the DataSource bean is missing or conditional (test profile without a database), refactoring constructor order, or copy-pasted setup code where the datasource variable name changed.

Related errors


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