{"record":{"id":"3fa62bd80a490fcb","repo":"mybatis/mybatis-3","slug":"parameter-id-must-not-be-null","errorCode":null,"errorMessage":"Parameter 'id' must not be null","messagePattern":"Parameter 'id' must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/mapping/Environment.java","lineNumber":32,"sourceCode":" *    limitations under the License.\n */\npackage org.apache.ibatis.mapping;\n\nimport javax.sql.DataSource;\n\nimport org.apache.ibatis.transaction.TransactionFactory;\n\n/**\n * @author Clinton Begin\n */\npublic final class Environment {\n  private final String id;\n  private final TransactionFactory transactionFactory;\n  private final DataSource dataSource;\n\n  public Environment(String id, TransactionFactory transactionFactory, DataSource dataSource) {\n    if (id == null) {\n      throw new IllegalArgumentException(\"Parameter 'id' must not be null\");\n    }\n    if (transactionFactory == null) {\n      throw new IllegalArgumentException(\"Parameter 'transactionFactory' must not be null\");\n    }\n    this.id = id;\n    if (dataSource == null) {\n      throw new IllegalArgumentException(\"Parameter 'dataSource' must not be null\");\n    }\n    this.transactionFactory = transactionFactory;\n    this.dataSource = dataSource;\n  }\n\n  public static class Builder {\n    private final String id;\n    private TransactionFactory transactionFactory;\n    private DataSource dataSource;\n\n    public Builder(String id) {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/mapping/Environment.java#L14-L50","documentation":"Environment's constructor throws IllegalArgumentException when id is null. The id names the environment (e.g. 'development', 'production') inside the MyBatis Configuration and must be non-null even before transactionFactory/dataSource are checked.","triggerScenarios":"new Environment(null, txFactory, dataSource), or Environment.Builder with a null id string — commonly the id comes from a variable/config that was never set (null from a properties file lookup that silently failed).","commonSituations":"Building a Configuration programmatically from external config where the environment-name key is misspelled so the lookup returns null; refactoring XML <environments> to Java config and dropping the id.","solutions":["Supply a non-null environment id, e.g. new Environment(\"development\", factory, ds) or the XML default.","Trace where the null came from: log/validate the config lookup (key name, properties file loaded) before constructing.","If converting from XML, make sure the <environments default=...> id is carried over."],"exampleFix":"// before\nString envId = props.getProperty(\"env.name\"); // key misspelled -> null\nnew Environment(envId, txFactory, ds);\n\n// after\nString envId = props.getProperty(\"env.name\");\nif (envId == null) throw new IllegalStateException(\"env.name missing in config\");\nnew Environment(envId, txFactory, ds);","handlingStrategy":"validation","validationCode":"String envId = Objects.requireNonNull(config.get(\"env.id\"), \"env.id must be configured\");\nEnvironment env = new Environment(envId, txFactory, ds);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fail fast with a descriptive message when reading the environment name from external config.","Use constants for environment ids instead of stringly-typed lookups scattered in code.","Cover config loading with a startup smoke test that builds the Environment."],"tags":["mybatis","configuration","null-check"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}