{"record":{"id":"76cd3e561fb1c533","repo":"baomidou/mybatis-plus","slug":"url-cannot-be-empty","errorCode":null,"errorMessage":"`url` cannot be empty","messagePattern":"`url` cannot be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/DataSourceConfig.java","lineNumber":372,"sourceCode":"    public static class Builder implements IConfigBuilder<DataSourceConfig> {\n\n        private final DataSourceConfig dataSourceConfig;\n\n        private Builder() {\n            this.dataSourceConfig = new DataSourceConfig();\n        }\n\n        /**\n         * 构造初始化方法\n         *\n         * @param url      数据库连接地址\n         * @param username 数据库账号\n         * @param password 数据库密码\n         */\n        public Builder(@NotNull String url, String username, String password) {\n            this();\n            if (StringUtils.isBlank(url)) {\n                throw new IllegalArgumentException(\"`url` cannot be empty\");\n            }\n            this.dataSourceConfig.url = url;\n            this.dataSourceConfig.username = username;\n            this.dataSourceConfig.password = password;\n        }\n\n        /**\n         * 构造初始化方法\n         *\n         * @param dataSource 外部数据源实例\n         */\n        public Builder(@NotNull DataSource dataSource) {\n            this();\n            this.dataSourceConfig.dataSource = dataSource;\n            try {\n                Connection conn = dataSource.getConnection();\n                this.dataSourceConfig.url = conn.getMetaData().getURL();\n                try {","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/DataSourceConfig.java#L354-L390","documentation":"DataSourceConfig.Builder's primary constructor requires a non-blank JDBC URL; passing null, empty, or whitespace-only url throws IllegalArgumentException('`url` cannot be empty') before any connection is attempted. This is a fail-fast guard in the code generator (mybatis-plus-generator) so a useless DataSource is never constructed.","triggerScenarios":"Building a generator DataSourceConfig with a url that resolved to null/blank at runtime — reading it from a config property that is unset, an environment variable missing in CI, a typo'd property key, or string concatenation producing empty.","commonSituations":"Generator run from Maven/Gradle or CLI where the db URL property lives in a profile not activated; CI pipelines missing the DB_URL environment variable; property placeholder not resolved (literal '${db.url}' also fails later, unset ones fail here).","solutions":["Supply a concrete, correct JDBC URL (jdbc:mysql://host:3306/db, jdbc:postgresql://..., etc.) to the Builder.","If it comes from config/env, validate it is present and non-blank before building (fail with a clear message about which property is missing).","Check for typos in the property/env name and that the activated profile actually defines it.","Alternatively pass a pre-built DataSource instance to the Builder(DataSource) overload when URL assembly is complex."],"exampleFix":"// before\nnew DataSourceConfig.Builder(url, user, pass).build(); // url null when env var missing\n\n// after\nString url = System.getenv(\"DB_URL\");\nif (StringUtils.isBlank(url)) {\n    throw new IllegalStateException(\"DB_URL env variable is required for code generation\");\n}\nnew DataSourceConfig.Builder(url, user, pass).build();","handlingStrategy":"validation","validationCode":"String url = System.getenv(\"DB_URL\");\nif (StringUtils.isBlank(url)) {\n    throw new IllegalStateException(\"DB_URL must be set (e.g. jdbc:mysql://host:3306/db)\");\n}\nnew DataSourceConfig.Builder(url, user, pass).build();","typeGuard":"static boolean isUsableJdbcUrl(String url) {\n    return url != null && !url.trim().isEmpty() && url.startsWith(\"jdbc:\");\n}","tryCatchPattern":"try {\n    dsConfig = new DataSourceConfig.Builder(url, user, pass).build();\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Generator datasource misconfigured: DB URL missing — check env/profile\", e);\n}","preventionTips":["Fail fast on blank config values at startup with messages naming the exact property/env var.","Keep generator DB config in one place and cover it with a presence check in CI."],"tags":["code-generator","configuration","jdbc","fail-fast"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}