apache/beam · error · RuntimeException

null driver given by driver provider

Error message

null driver given by driver provider

What it means

ReadFn/WriteUnwindFn's createDriver() invokes the user-supplied driverProviderFn and checks that a non-null org.neo4j.driver.Driver comes back. The provider returned null (Driver is an interface, so the type system cannot catch this), so the DoFn cannot connect to Neo4j and fails at setup/use time.

Solutions

  1. Make the driver provider always return a real Driver: build it with GraphDatabase.driver(uri, AuthTokens.basic(user, password)).
  2. Throw a descriptive exception inside the provider when configuration is missing instead of returning null.
  3. Log/validate connection parameters before the pipeline runs so the provider never hits the null path.

Example fix

// before
.withDriverProviderFn(config -> config.isComplete() ? null : buildDriver(config))
// after
.withDriverProviderFn(config -> {
  if (!config.isComplete()) { throw new IllegalArgumentException("Incomplete Neo4j config"); }
  return GraphDatabase.driver(config.getUri(), AuthTokens.basic(config.getUser(), config.getPassword()));
})
Defensive patterns

Strategy: validation

Validate before calling

Driver d = driverProviderFn.apply(null); if (d == null) throw new IllegalStateException("driver provider must return a Driver");

Prevention

When it happens

Trigger: A driverProviderFn lambda or SerializableFunction that returns null — e.g. a factory that short-circuits on bad config, memoized supplier that failed silently, or code path returning null instead of throwing.

Common situations: Config-driven driver factories that return null when URL/credentials are missing; test doubles (mocks) returning null; swallowing exceptions inside the provider and falling through with a null return.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/286b7f3241ba803d. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/io/neo4j/src/main/java/org/apache/beam/sdk/io/neo4j/Neo4jIO.java:706

        @NonNull SerializableFunction<Void, Driver> driverProviderFn,
        @NonNull SessionConfig sessionConfig,
        @NonNull TransactionConfig transactionConfig) {
      this.driverProviderFn = driverProviderFn;
      this.sessionConfig = sessionConfig;
      this.transactionConfig = transactionConfig;
      this.driverSession = DriverSession.emptyClosed();
    }

    /**
     * Delay the creation of driver and session until we actually have data to do something with.
     */
    @Setup
    public void setup() {}

    protected @NonNull Driver createDriver() {
      Driver driver = driverProviderFn.apply(null);
      if (driver == null) {
        throw new RuntimeException("null driver given by driver provider");
      }
      return driver;
    }

    protected @Initialized @NonNull DriverSession buildDriverSession() {
      @NonNull Driver driver = createDriver();
      @NonNull Session session = driver.session(sessionConfig);
      return new DriverSession(driver, session);
    }

    @StartBundle
    public void startBundle() {
      if (driverSession == null || driverSession.closed.get()) {
        driverSession = buildDriverSession();
      }
    }

    @FinishBundle

View on GitHub (pinned to 12126d8942)