{"record":{"id":"eaf47121c3b1814d","repo":"apache/beam","slug":"databaseid-can-t-be-empty","errorCode":null,"errorMessage":"databaseId can't be empty","messagePattern":"databaseId can't be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerTransformRegistrar.java","lineNumber":128,"sourceCode":"\n    public void setPlainText(@Nullable Boolean plainText) {\n      this.plainText = plainText;\n    }\n\n    public void setClientCertPath(@Nullable String clientCertPath) {\n      this.clientCertPath = clientCertPath;\n    }\n\n    public void setClientCertKeyPath(@Nullable String clientCertKeyPath) {\n      this.clientCertKeyPath = clientCertKeyPath;\n    }\n\n    void checkMandatoryFields() {\n      if (projectId.isEmpty()) {\n        throw new IllegalArgumentException(\"projectId can't be empty\");\n      }\n      if (databaseId.isEmpty()) {\n        throw new IllegalArgumentException(\"databaseId can't be empty\");\n      }\n      if (instanceId.isEmpty()) {\n        throw new IllegalArgumentException(\"instanceId can't be empty\");\n      }\n      if ((clientCertPath != null) != (clientCertKeyPath != null)) {\n        throw new IllegalArgumentException(\n            \"Both clientCertPath and clientCertKeyPath must be specified together.\");\n      }\n    }\n  }\n\n  public static class ReadBuilder\n      implements ExternalTransformBuilder<ReadBuilder.Configuration, PBegin, PCollection<Row>> {\n\n    public static class Configuration extends CrossLanguageConfiguration {\n      // TODO: https://github.com/apache/beam/issues/20415 Come up with something to determine\n      // schema without this explicit parameter\n      private Schema schema = Schema.builder().build();","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerTransformRegistrar.java#L110-L146","documentation":"SpannerTransformRegistrar's checkMandatoryFields() validates that the Spanner connector configuration includes a projectId, databaseId, and instanceId before building any read/write transform. This error is thrown when the databaseId field is set to an empty string (or never set), because a Cloud Spanner database path cannot be constructed without it. It is a fail-fast guard so the job fails at pipeline-construction time rather than deep inside the runner.","triggerScenarios":"Building a SpannerIO.Read/Write transform (or external transform via the registrar) with databaseId(\"\"), leaving databaseId unset on the builder, or populating the configuration from a map/JSON/CLI option where the databaseId key is present but blank.","commonSituations":"Environment variable or template parameter for the Spanner database is unset and defaulted to \"\"; typos like setDatabaseId vs setDatabaseName; YAML/JSON pipeline configs where the database field was removed; programmatic pipelines that pass through user-supplied options without validation.","solutions":["Call .withDatabaseId(\"<your-database>\") on the Spanner builder with a non-empty database name.","If the value comes from an option/env var, check it is non-empty before building the transform (e.g. requireNonNull(options.getSpannerDatabase()).isEmpty() guard).","Verify the database exists with `gcloud spanner databases list --instance=<instance>` and use its exact name."],"exampleFix":"// before\nSpannerIO.Read read = SpannerIO.read().withInstanceId(\"my-instance\").withProjectId(\"my-project\");\n// after\nSpannerIO.Read read = SpannerIO.read().withProjectId(\"my-project\").withInstanceId(\"my-instance\").withDatabaseId(\"my-database\");","handlingStrategy":"validation","validationCode":"if (databaseId == null || databaseId.isEmpty()) { throw new IllegalArgumentException(\"databaseId must be set before building the Spanner transform\"); }","typeGuard":null,"tryCatchPattern":"try { SpannerIO.read().withProjectId(p).withInstanceId(i).withDatabaseId(db); } catch (IllegalArgumentException e) { log.error(\"Spanner config incomplete: {}\", e.getMessage()); throw new ConfigException(e); }","preventionTips":["Validate projectId/instanceId/databaseId together in one pre-flight check before building transforms.","Fail pipeline-option parsing early when required Spanner options are blank.","Use Objects.requireNonNull plus isEmpty checks on all option getters."],"tags":["java","apache-beam","google-cloud-spanner","validation"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}