{"record":{"id":"286b7f3241ba803d","repo":"apache/beam","slug":"null-driver-given-by-driver-provider","errorCode":null,"errorMessage":"null driver given by driver provider","messagePattern":"null driver given by driver provider","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/neo4j/src/main/java/org/apache/beam/sdk/io/neo4j/Neo4jIO.java","lineNumber":706,"sourceCode":"        @NonNull SerializableFunction<Void, Driver> driverProviderFn,\n        @NonNull SessionConfig sessionConfig,\n        @NonNull TransactionConfig transactionConfig) {\n      this.driverProviderFn = driverProviderFn;\n      this.sessionConfig = sessionConfig;\n      this.transactionConfig = transactionConfig;\n      this.driverSession = DriverSession.emptyClosed();\n    }\n\n    /**\n     * Delay the creation of driver and session until we actually have data to do something with.\n     */\n    @Setup\n    public void setup() {}\n\n    protected @NonNull Driver createDriver() {\n      Driver driver = driverProviderFn.apply(null);\n      if (driver == null) {\n        throw new RuntimeException(\"null driver given by driver provider\");\n      }\n      return driver;\n    }\n\n    protected @Initialized @NonNull DriverSession buildDriverSession() {\n      @NonNull Driver driver = createDriver();\n      @NonNull Session session = driver.session(sessionConfig);\n      return new DriverSession(driver, session);\n    }\n\n    @StartBundle\n    public void startBundle() {\n      if (driverSession == null || driverSession.closed.get()) {\n        driverSession = buildDriverSession();\n      }\n    }\n\n    @FinishBundle","sourceCodeStart":688,"sourceCodeEnd":724,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/neo4j/src/main/java/org/apache/beam/sdk/io/neo4j/Neo4jIO.java#L688-L724","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Make the driver provider always return a real Driver: build it with GraphDatabase.driver(uri, AuthTokens.basic(user, password)).","Throw a descriptive exception inside the provider when configuration is missing instead of returning null.","Log/validate connection parameters before the pipeline runs so the provider never hits the null path."],"exampleFix":"// before\n.withDriverProviderFn(config -> config.isComplete() ? null : buildDriver(config))\n// after\n.withDriverProviderFn(config -> {\n  if (!config.isComplete()) { throw new IllegalArgumentException(\"Incomplete Neo4j config\"); }\n  return GraphDatabase.driver(config.getUri(), AuthTokens.basic(config.getUser(), config.getPassword()));\n})","handlingStrategy":"validation","validationCode":"Driver d = driverProviderFn.apply(null); if (d == null) throw new IllegalStateException(\"driver provider must return a Driver\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never return null from driverProviderFn; throw on missing config instead.","Smoke-test the provider locally with a try (Session s = driver.session()) before running the pipeline.","Avoid mocks returning null in integration tests."],"tags":["java","neo4j","apache-beam","null-return"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}