This is an automated email from the ASF dual-hosted git repository.

terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new fdd58d899c3 Validate database rule configurations before checker 
lookup (#39883)
fdd58d899c3 is described below

commit fdd58d899c30e92e02edd947b5a5ddaedc64da6f
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Sep 18 09:29:29 2026 +0800

    Validate database rule configurations before checker lookup (#39883)
---
 .../rule/checker/DatabaseRuleConfigurationCheckEngine.java       | 2 ++
 .../rule/checker/DatabaseRuleConfigurationCheckEngineTest.java   | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/checker/DatabaseRuleConfigurationCheckEngine.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/checker/DatabaseRuleConfigurationCheckEngine.java
index 9eb3e25b17c..86cca726bba 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/checker/DatabaseRuleConfigurationCheckEngine.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/checker/DatabaseRuleConfigurationCheckEngine.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.infra.config.rule.checker;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import 
org.apache.shardingsphere.infra.config.rule.validator.RuleConfigurationValidator;
 import org.apache.shardingsphere.infra.exception.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.DuplicateRuleException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -46,6 +47,7 @@ public final class DatabaseRuleConfigurationCheckEngine {
      */
     @SuppressWarnings({"unchecked", "rawtypes"})
     public static void check(final RuleConfiguration ruleConfig, final 
ShardingSphereDatabase database) {
+        RuleConfigurationValidator.validate(ruleConfig);
         DatabaseRuleConfigurationChecker checker = 
OrderedSPILoader.getServicesByClass(DatabaseRuleConfigurationChecker.class, 
Collections.singleton(ruleConfig.getClass())).get(ruleConfig.getClass());
         if (null == checker) {
             // TODO Remove after implementing the checker of 
BroadcastRuleConfiguration and SingleRuleConfiguration
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/rule/checker/DatabaseRuleConfigurationCheckEngineTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/rule/checker/DatabaseRuleConfigurationCheckEngineTest.java
index 3e003184671..9df3d2bf029 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/rule/checker/DatabaseRuleConfigurationCheckEngineTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/rule/checker/DatabaseRuleConfigurationCheckEngineTest.java
@@ -18,12 +18,14 @@
 package org.apache.shardingsphere.infra.config.rule.checker;
 
 import 
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.DuplicateRuleException;
+import 
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.InvalidRuleConfigurationException;
 import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
 import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
 import 
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
+import 
org.apache.shardingsphere.infra.rule.builder.fixture.FixtureDatabaseRuleConfiguration;
 import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
 import 
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
 import 
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
@@ -80,6 +82,13 @@ class DatabaseRuleConfigurationCheckEngineTest {
         assertDoesNotThrow(() -> 
DatabaseRuleConfigurationCheckEngine.check(new FixtureRuleConfiguration(), 
database));
     }
     
+    @Test
+    void assertCheckInvalidConfigurationWithoutChecker() {
+        FixtureDatabaseRuleConfiguration ruleConfig = new 
FixtureDatabaseRuleConfiguration();
+        ruleConfig.setName("");
+        assertThrows(InvalidRuleConfigurationException.class, () -> 
DatabaseRuleConfigurationCheckEngine.check(ruleConfig, database));
+    }
+    
     @Test
     void assertCheckWithEmptyDataSourcesAndTables() {
         
when(OrderedSPILoader.getServicesByClass(DatabaseRuleConfigurationChecker.class,
 Collections.singleton(FixtureRuleConfiguration.class)))

Reply via email to