{"record":{"id":"351628b6390e59a5","repo":"alibaba/spring-ai-alibaba","slug":"dbtype-cannot-be-null-or-blank","errorCode":null,"errorMessage":"dbType cannot be null or blank","messagePattern":"dbType cannot be null or blank","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/DatabaseStore.java","lineNumber":207,"sourceCode":"            case \"postgresql\", \"postgres\", \"pgsql\" -> \"jdbc:postgresql://\" + host + \":\" + port + \"/\" + database;\n            case \"oracle\" -> \"jdbc:oracle:thin:@\" + host + \":\" + port + \":\" + database;\n            case \"h2\" -> \"jdbc:h2:mem:\" + database + \";DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE\";\n            default -> throw new IllegalArgumentException(\n                    \"Unsupported dbType: \" + dbType + \". Supported values: mysql, postgresql, oracle, h2\");\n        };\n    }\n\n    /**\n     * Validate connection parameters for JDBC URL construction.\n     *\n     * @param dbType   database type\n     * @param host     database host\n     * @param port     database port\n     * @param database database name\n     */\n    private static void validateConnectionInfo(String dbType, String host, int port, String database) {\n        if (dbType == null || dbType.isBlank()) {\n            throw new IllegalArgumentException(\"dbType cannot be null or blank\");\n        }\n        if (host == null || host.isBlank()) {\n            throw new IllegalArgumentException(\"host cannot be null or blank\");\n        }\n        if (port <= 0) {\n            throw new IllegalArgumentException(\"port must be greater than 0\");\n        }\n        if (database == null || database.isBlank()) {\n            throw new IllegalArgumentException(\"database cannot be null or blank\");\n        }\n    }\n\n    /**\n     * Resolve table name with backward-compatible default behavior.\n     *\n     * @param tableName candidate table name\n     * @return resolved table name\n     */","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/DatabaseStore.java#L189-L225","documentation":"DatabaseStore builds a JDBC URL from connection parameters and first validates them via validateConnectionInfo. This IllegalArgumentException is thrown when the dbType parameter is null or an empty/whitespace-only string, because no dialect or URL prefix can be derived without it.","triggerScenarios":"Calling buildJdbcUrl (directly or via DatabaseStore configuration) with dbType null or blank, e.g. a missing 'dbType' entry in a config map/properties file that is passed through as null.","commonSituations":"YAML/properties config omits the database type key; environment variable for DB type not set and defaulted to null; caller passes an uninitialized String variable instead of 'mysql'/'postgresql'/'oracle'/'h2'.","solutions":["Set dbType to one of the supported values (H2, MySQL, PostgreSQL, Oracle) in the store configuration","Check that the config key or environment variable supplying dbType is present and non-blank before constructing DatabaseStore","Fail fast at startup: validate all connection properties before calling buildJdbcUrl"],"exampleFix":"// before\nDatabaseStore.builder().dbType(config.get(\"dbType\")).build();\n// after\nString dbType = Objects.requireNonNull(config.get(\"dbType\"), \"dbType must be set\");\nDatabaseStore.builder().dbType(dbType).build();","handlingStrategy":"validation","validationCode":"if (dbType == null || dbType.isBlank()) throw new IllegalArgumentException(\"dbType must be set before building the store\");","typeGuard":"boolean hasDbType(java.util.Map<String,String> cfg) { return cfg.get(\"dbType\") != null && !cfg.get(\"dbType\").isBlank(); }","tryCatchPattern":"try { store = DatabaseStore.builder().dbType(dbType).build(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"dbType\")) { log.error(\"Missing dbType config\"); } throw e; }","preventionTips":["Define dbType in a required config block validated at startup","Use an enum for dbType instead of free-form strings","Add a unit test asserting store construction fails fast on blank dbType"],"tags":["database","configuration","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-14T05:17:10.506Z"}