openzipkin/zipkin · error · NullPointerException

sessionFactory == null

Error message

sessionFactory == null

What it means

Thrown by CassandraStorageBuilder.sessionFactory() when the caller passes null. The builder enforces that a non-null CassandraStorage.SessionFactory is set; it is used to override how CqlSession objects are created. This is a fail-fast guard so the builder never stores a null factory that would blow up later at session creation time.

Source

Thrown at zipkin-storage/cassandra/src/main/java/zipkin2/storage/cassandra/CassandraStorageBuilder.java:155

    return (B) this;
  }

  /** Controls validation of Cassandra server hostname. Defaults to true. */
  public B sslHostnameValidation(boolean sslHostnameValidation) {
    this.sslHostnameValidation = sslHostnameValidation;
    return (B) this;
  }

  /** Keyspace to store span and index data. Defaults to "zipkin3" */
  public B keyspace(String keyspace) {
    if (keyspace == null) throw new NullPointerException("keyspace == null");
    this.keyspace = keyspace;
    return (B) this;
  }

  /** Override to control how sessions are created. */
  public B sessionFactory(CassandraStorage.SessionFactory sessionFactory) {
    if (sessionFactory == null) throw new NullPointerException("sessionFactory == null");
    this.sessionFactory = sessionFactory;
    return (B) this;
  }

  public B ensureSchema(boolean ensureSchema) {
    if (ensureSchema) {
      this.ensureSchema = Schema::ensure;
    } else {
      this.ensureSchema = Schema::validate;
    }
    return (B) this;
  }

  /**
   * Spans have multiple values for the same id. For example, a client and server contribute to the
   * same span id. When searching for spans by id, the amount of results may be larger than the ids.
   * This defines a threshold which accommodates this situation, without looking for an unbounded
   * number of results.

View on GitHub (pinned to 878ce2a1fa)

Solutions

  1. Pass a real CassandraStorage.SessionFactory implementation, e.g. (storage, metrics) -> new CqlSessionBuilder(...) or the default Zipkin one.
  2. If the value comes from config/DI, check it for null before calling sessionFactory() and fix the binding or property that produced null.
  3. If you do not need a custom factory, simply omit the sessionFactory() call; the builder has a default.

Example fix

// before
CassandraStorage.newBuilder().sessionFactory(maybeNullFactory).keyspace("zipkin").build();

// after
CassandraStorage.Builder<?> b = CassandraStorage.newBuilder().keyspace("zipkin");
if (maybeNullFactory != null) b = b.sessionFactory(maybeNullFactory);
b.build();
Defensive patterns

Strategy: validation

Validate before calling

if (factory == null) throw new IllegalStateException("sessionFactory not configured; check DI bindings");
storageBuilder.sessionFactory(factory);

Prevention

When it happens

Trigger: Calling CassandraStorage.newBuilder().sessionFactory(null), or wiring the factory from a variable/config value that resolved to null (e.g. a lookup or dependency-injection provider that returned null).

Common situations: Conditional session-factory configuration where the custom factory is only created in some branches; copying example code that references a factory class not on the classpath; DI containers that inject null when the binding is missing.

Related errors


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