{"record":{"id":"6a6fa00eb8db165a","repo":"alibaba/spring-ai-alibaba","slug":"port-must-be-greater-than-0","errorCode":null,"errorMessage":"port must be greater than 0","messagePattern":"port must be greater than 0","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":741,"sourceCode":"\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\"));\n\t\t\t\tds.setPassword(requireNonNull(password, \"password cannot be null\"));\n\t\t\t\tds.setPortNumbers(new int[] {port});\n\t\t\t\tds.setServerNames(new String[] {requireNotBlank(host, \"host\")});\n\t\t\t\tdatasource = ds;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\treturn new PostgresSaver(this);\n\t\t\t}\n\t\t\tcatch (SQLException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":723,"sourceCodeEnd":759,"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#L723-L759","documentation":"PostgresSaver.Builder.build() requires a positive port when no external DataSource was supplied, since it constructs a PGSimpleDataSource itself. A null or non-positive port throws this IllegalArgumentException before any connection is attempted.","triggerScenarios":"Building a saver without setting datasource(...) and without port(...) or with port(0)/port(-5432) — commonly when the port config property is missing or parsed as 0.","commonSituations":"Missing DB_PORT env var defaulted to 0; tests that set a DataSource don't hit this, so it surfaces only in production wiring; port mapping mistakes in Docker Compose.","solutions":["Set a valid port, e.g. builder.port(5432) for default Postgres.","Or inject your own DataSource via builder.datasource(...) to bypass port validation (useful in tests).","Fix the config source so the port property resolves to a positive integer."],"exampleFix":"// before\nPostgresSaver.builder().host(host).database(db).user(u).password(p).build();\n// after\nPostgresSaver.builder().host(host).port(5432).database(db).user(u).password(p).build();","handlingStrategy":"validation","validationCode":"if (dataSource == null && (port == null || port <= 0)) {\n    throw new IllegalStateException(\"Provide port(...) > 0 or a DataSource\");\n}","typeGuard":null,"tryCatchPattern":"try { return builder.build(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"port\")) builder.port(5432); return builder.build(); }","preventionTips":["Always set port when not supplying a DataSource","Default to 5432 for standard Postgres","Parse port config with validation, not raw Integer.parseInt"],"tags":["configuration","postgresql","builder-validation"],"backgroundTag":"missing-required-config-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"}