{"record":{"id":"d377abf9e228c05f","repo":"baomidou/mybatis-plus","slug":"include-and-exclude-configurations-are-mutuall","errorCode":null,"errorMessage":"`include` and `exclude` configurations are mutually exclusive and cannot be used simultaneously.","messagePattern":"`include` and `exclude` configurations are mutually exclusive and cannot be used simultaneously\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java","lineNumber":270,"sourceCode":"     * 表名称匹配过滤表前缀\n     *\n     * @param tableName 表名称\n     * @since 3.3.2\n     */\n    public boolean startsWithTablePrefix(@NotNull String tableName) {\n        return this.tablePrefix.stream().anyMatch(tableName::startsWith);\n    }\n\n    /**\n     * 验证配置项\n     *\n     * @since 3.5.0\n     */\n    public void validate() {\n        boolean isInclude = !this.getInclude().isEmpty();\n        boolean isExclude = !this.getExclude().isEmpty();\n        if (isInclude && isExclude) {\n            throw new IllegalArgumentException(\"`include` and `exclude` configurations are mutually exclusive and cannot be used simultaneously.\");\n        }\n        if (this.getNotLikeTable() != null && this.getLikeTable() != null) {\n            throw new IllegalArgumentException(\"`likeTable` and `notLikeTable` configurations are mutually exclusive and cannot be used simultaneously.\");\n        }\n    }\n\n    /**\n     * 包含表名匹配\n     *\n     * @param tableName 表名\n     * @return 是否匹配\n     * @since 3.5.0\n     */\n    public boolean matchIncludeTable(@NotNull String tableName) {\n        return matchTable(tableName, this.getInclude());\n    }\n\n    /**","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java#L252-L288","documentation":"StrategyConfig.validate() throws IllegalArgumentException when both include and exclude table lists are non-empty at generation time. The two filters are semantically contradictory (generate ONLY these vs generate all EXCEPT these), so the library rejects the combination instead of guessing precedence.","triggerScenarios":"Building a FastAutoGenerator/AutoGenerator whose StrategyConfig has both .include(...) (or includePrefix/addInclude) and .exclude(...) (or notLikeTable-adjacent exclude methods) populated, then calling generate() which invokes validate().","commonSituations":"Copy-pasting strategy configuration from two examples into one config; incrementally adding .exclude(\"tmp_x\") to a config that already had .include(\"sys_user\") and forgetting the two cannot coexist.","solutions":["Keep only one of the two filters: if you want an allow-list, remove the exclude(...) call; if you want a deny-list, remove the include(...) call.","If you need both semantics, express the deny part by trimming the include list yourself before configuring it (e.g. include.removeAll(excluded)).","Run strategyConfig.validate() early in a unit test so misconfiguration fails fast with a clear message instead of at generate time."],"exampleFix":"// before\nStrategyConfig strategy = new StrategyConfig();\nstrategy.addInclude(\"sys_user\", \"sys_role\");\nstrategy.addExclude(\"sys_log\"); // throws on validate()\n\n// after\nStrategyConfig strategy = new StrategyConfig();\nstrategy.addInclude(\"sys_user\", \"sys_role\"); // deny-list removed","handlingStrategy":"validation","validationCode":"// Call validate() yourself at startup to fail fast with the clear message\nstrategyConfig.validate();\n// or pre-check:\nif (!strategyConfig.getInclude().isEmpty() && !strategyConfig.getExclude().isEmpty()) {\n    throw new IllegalArgumentException(\"choose include OR exclude\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one filtering style (allow-list or deny-list) per project and forbid the other in code review.","Invoke StrategyConfig.validate() in a @BeforeAll/unit test of the generator configuration.","Build StrategyConfig in one factory method so contradictory calls cannot be scattered."],"tags":["mybatis-plus","code-generator","configuration","validation"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}