{"record":{"id":"246f8504431e8830","repo":"alibaba/spring-ai-alibaba","slug":"s-cannot-be-blank-246f85","errorCode":null,"errorMessage":"'%s' cannot be blank","messagePattern":"'(.+?)' cannot be blank","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/checkpoint/savers/postgresql/PostgresSaver.java","lineNumber":727,"sourceCode":"\t\t/**\n\t\t * @deprecated Use {@link #createOption(CreateOption)} instead.\n\t\t * Sets whether to drop tables before creating them.\n\t\t * @param dropTablesFirst true to drop tables first\n\t\t * @return this builder\n\t\t */\n\t\t@Deprecated\n\t\tpublic Builder dropTablesFirst(boolean dropTablesFirst) {\n\t\t\tthis.dropTablesFirst = dropTablesFirst;\n\t\t\t// Convert to CreateOption for backward compatibility\n\t\t\tif (dropTablesFirst && this.createOption != CreateOption.CREATE_NONE) {\n\t\t\t\tthis.createOption = CreateOption.CREATE_OR_REPLACE;\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tprivate String requireNotBlank(String value, String name) {\n\t\t\tif (requireNonNull(value, format(\"'%s' cannot be null\", name)).isBlank()) {\n\t\t\t\tthrow new IllegalArgumentException(format(\"'%s' cannot be blank\", name));\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\n\t\tpublic PostgresSaver build() {\n\t\t\tif (stateSerializer == null) {\n\t\t\t\tlog.info(\"No StateSerializer for saver provided, using default SpringAiJacksonStateSerializer, please make sure saver uses the same serializer of the graph.\");\n\t\t\t\tthis.stateSerializer = StateGraph.DEFAULT_JACKSON_SERIALIZER;\n\t\t\t}\n\n\t\t\t// If datasource is already set (e.g., for testing), use it directly\n\t\t\tif (datasource == null) {\n\t\t\t\tif (port == null || port <= 0) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"port must be greater than 0\");\n\t\t\t\t}\n\t\t\t\tvar ds = new PGSimpleDataSource();\n\t\t\t\tds.setDatabaseName(requireNotBlank(database, \"database\"));\n\t\t\t\tds.setUser(requireNotBlank(user, \"user\"));","sourceCodeStart":709,"sourceCodeEnd":745,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/checkpoint/savers/postgresql/PostgresSaver.java#L709-L745","documentation":"Builder.requireNotBlank rejects null or whitespace-only required string settings (database name, user, etc.), formatting the field name into the message. It is builder-time validation ensuring mandatory connection parameters are present and non-empty.","triggerScenarios":"Calling database(null), user(\"\"), or user(\"   \") on PostgresSaver.Builder, typically from blank config values loaded from environment variables or application.yml.","commonSituations":"Unset env var interpolated as empty string in YAML; placeholder not replaced (${DB_USER} unresolved); trimming issues where a field contains only spaces.","solutions":["Provide the required non-blank value in the builder (database(...), user(...)).","Check the originating config file/env var is set and not just whitespace; trim before passing.","Add startup validation of your own configuration before building the saver to fail with a clearer message."],"exampleFix":"// before\nString user = env.get(\"DB_USER\"); // may be \"\"\nbuilder.user(user);\n// after\nString user = env.get(\"DB_USER\");\nif (user == null || user.isBlank()) throw new IllegalStateException(\"DB_USER must be set\");\nbuilder.user(user.trim());","handlingStrategy":"validation","validationCode":"static void requireConfigValue(String v, String name) {\n    if (v == null || v.isBlank()) throw new IllegalStateException(name + \" must be set and non-blank\");\n}\n// usage: requireConfigValue(env.get(\"DB_USER\"), \"DB_USER\");","typeGuard":null,"tryCatchPattern":"try { builder.user(raw); } catch (IllegalArgumentException e) { throw new IllegalStateException(\"Check DB user config: \" + e.getMessage(), e); }","preventionTips":["Trim and check env vars before passing to builders","Fail fast on blank config at app startup","Watch for unresolved ${PLACEHOLDER} values in YAML"],"tags":["configuration","builder-validation","postgresql"],"backgroundTag":"empty-required-field","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}