{"record":{"id":"43d0ce3a9e55565c","repo":"apache/beam","slug":"neo4j-session-was-not-initialized-correctly","errorCode":null,"errorMessage":"neo4j session was not initialized correctly","messagePattern":"neo4j session was not initialized correctly","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":847,"sourceCode":"            return count;\n          };\n\n      if (logCypher) {\n        String parametersString = getParametersString(parametersMap);\n\n        String readWrite = writeTransaction ? \"write\" : \"read\";\n        LOG.info(\n            \"Starting a {} transaction for cypher: {}, parameters: {}\",\n            readWrite,\n            cypher,\n            parametersString);\n      }\n\n      // There are 2 ways to do a transaction on Neo4j: read or write\n      // It's important that the right type is selected, especially in clustered configurations.\n      //\n      if (driverSession.session == null) {\n        throw new RuntimeException(\"neo4j session was not initialized correctly\");\n      } else {\n        final Long count;\n        if (writeTransaction) {\n          count = driverSession.session.writeTransaction(transactionWork, transactionConfig);\n        } else {\n          count = driverSession.session.readTransaction(transactionWork, transactionConfig);\n        }\n        LOG.debug(\"Retrieved {} elements from Neo4J\", count);\n      }\n    }\n  }\n\n  /**\n   * Wraps a {@link DriverConfiguration} to provide a {@link Driver}.\n   *\n   * <p>At most a single {@link Driver} instance will be constructed during pipeline execution for\n   * each unique {@link DriverConfiguration} within the pipeline.\n   */","sourceCodeStart":829,"sourceCodeEnd":865,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/neo4j/src/main/java/org/apache/beam/sdk/io/neo4j/Neo4jIO.java#L829-L865","documentation":"ReadFn.processElement checks that the lazily initialized Neo4j session inside the driverSession holder is non-null before running the read/write transaction. A null session means the @Setup/start bundle initialization failed to create a session (e.g. driver creation problem or state not initialized for this worker), so the read cannot proceed.","triggerScenarios":"driverSession.session is null at transaction time — typically because session initialization silently produced null, a worker reused a DoFn instance whose setup path didn't run/complete, or a custom subclass overrode initialization.","commonSituations":"Custom DoFn subclasses that bypass buildDriverSession; test harnesses invoking processElement without Setup; runner state issues after worker restart/reuse.","solutions":["Ensure the standard ReadFn/Neo4jIO lifecycle is used (let Beam call @Setup) rather than manually instantiating the DoFn.","If subclassing, always call super / buildDriverSession() and never assign session to null.","Retry the bundle; if reproducible, inspect worker logs for earlier driver-creation failures that left session unset."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if (driverSession.session == null) { throw new IllegalStateException(\"session not initialized; ensure Beam lifecycle (@Setup) ran\"); }","preventionTips":["Do not instantiate ReadFn manually; rely on Beam's DoFn lifecycle.","Call super.buildDriverSession() in subclasses.","Retry failing bundles before treating as fatal."],"tags":["java","neo4j","apache-beam","initialization"],"backgroundTag":"internal-invariant-violation","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"}