{"record":{"id":"c8b90ab7fec2d7d8","repo":"openzipkin/zipkin","slug":"sessionfactory-null","errorCode":null,"errorMessage":"sessionFactory == null","messagePattern":"sessionFactory == null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"zipkin-storage/cassandra/src/main/java/zipkin2/storage/cassandra/CassandraStorageBuilder.java","lineNumber":155,"sourceCode":"    return (B) this;\n  }\n\n  /** Controls validation of Cassandra server hostname. Defaults to true. */\n  public B sslHostnameValidation(boolean sslHostnameValidation) {\n    this.sslHostnameValidation = sslHostnameValidation;\n    return (B) this;\n  }\n\n  /** Keyspace to store span and index data. Defaults to \"zipkin3\" */\n  public B keyspace(String keyspace) {\n    if (keyspace == null) throw new NullPointerException(\"keyspace == null\");\n    this.keyspace = keyspace;\n    return (B) this;\n  }\n\n  /** Override to control how sessions are created. */\n  public B sessionFactory(CassandraStorage.SessionFactory sessionFactory) {\n    if (sessionFactory == null) throw new NullPointerException(\"sessionFactory == null\");\n    this.sessionFactory = sessionFactory;\n    return (B) this;\n  }\n\n  public B ensureSchema(boolean ensureSchema) {\n    if (ensureSchema) {\n      this.ensureSchema = Schema::ensure;\n    } else {\n      this.ensureSchema = Schema::validate;\n    }\n    return (B) this;\n  }\n\n  /**\n   * Spans have multiple values for the same id. For example, a client and server contribute to the\n   * same span id. When searching for spans by id, the amount of results may be larger than the ids.\n   * This defines a threshold which accommodates this situation, without looking for an unbounded\n   * number of results.","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin-storage/cassandra/src/main/java/zipkin2/storage/cassandra/CassandraStorageBuilder.java#L137-L173","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Pass a real CassandraStorage.SessionFactory implementation, e.g. (storage, metrics) -> new CqlSessionBuilder(...) or the default Zipkin one.","If the value comes from config/DI, check it for null before calling sessionFactory() and fix the binding or property that produced null.","If you do not need a custom factory, simply omit the sessionFactory() call; the builder has a default."],"exampleFix":"// before\nCassandraStorage.newBuilder().sessionFactory(maybeNullFactory).keyspace(\"zipkin\").build();\n\n// after\nCassandraStorage.Builder<?> b = CassandraStorage.newBuilder().keyspace(\"zipkin\");\nif (maybeNullFactory != null) b = b.sessionFactory(maybeNullFactory);\nb.build();","handlingStrategy":"validation","validationCode":"if (factory == null) throw new IllegalStateException(\"sessionFactory not configured; check DI bindings\");\nstorageBuilder.sessionFactory(factory);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make builder config values non-null at the source (env defaults or required-config checks) instead of relying on the builder's NPE.","In DI setups, add a binding validation so a missing SessionFactory fails at startup with a clear message."],"tags":["cassandra","zipkin","builder","null-check","configuration"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}