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

sunnianjun 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 60aaf2f7e6c Add ShardingSpherePreconditions.checkNotEmpty() (#30921)
60aaf2f7e6c is described below

commit 60aaf2f7e6c276ee7bbf55edc5305552b6b659e1
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Apr 16 23:42:39 2024 +0800

    Add ShardingSpherePreconditions.checkNotEmpty() (#30921)
---
 .../encrypt/algorithm/standard/AESEncryptAlgorithm.java   |  3 +--
 .../encrypt/checker/EncryptRuleConfigurationChecker.java  | 13 ++++++-------
 ...dwriteSplittingDataSourceRuleConfigurationChecker.java |  5 ++---
 .../update/AlterDefaultShadowAlgorithmExecutor.java       |  3 +--
 .../sharding/classbased/ClassBasedShardingAlgorithm.java  |  5 ++---
 .../sharding/datetime/IntervalShardingAlgorithm.java      |  4 +---
 .../sharding/inline/ComplexInlineShardingAlgorithm.java   |  3 +--
 .../sharding/inline/InlineShardingAlgorithm.java          |  3 +--
 .../checker/ShardingRuleConfigurationChecker.java         |  7 +++----
 .../infra/exception/core/ShardingSpherePreconditions.java | 15 +++++++++++++++
 .../exception/core/ShardingSpherePreconditionsTest.java   | 11 +++++++++++
 .../expr/interval/IntervalInlineExpressionParser.java     |  3 +--
 .../traffic/segment/SQLMatchTrafficAlgorithm.java         |  3 +--
 .../traffic/segment/SQLRegexTrafficAlgorithm.java         |  3 +--
 .../shardingsphere/mode/manager/ContextManager.java       |  3 +--
 .../util/YamlDatabaseConfigurationImportExecutor.java     |  3 +--
 .../authentication/OpenGaussAuthenticationEngine.java     |  2 +-
 .../authentication/PostgreSQLAuthenticationEngine.java    |  2 +-
 18 files changed, 51 insertions(+), 40 deletions(-)

diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
index d9bd78ff263..89bf5cdc6ca 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.encrypt.algorithm.standard;
 
-import com.google.common.base.Strings;
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.SneakyThrows;
@@ -59,7 +58,7 @@ public final class AESEncryptAlgorithm implements 
EncryptAlgorithm {
     
     private byte[] getSecretKey(final Properties props) {
         String aesKey = props.getProperty(AES_KEY);
-        ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(aesKey), 
() -> new AlgorithmInitializationException(this, "%s can not be null or empty", 
AES_KEY));
+        ShardingSpherePreconditions.checkNotEmpty(aesKey, () -> new 
AlgorithmInitializationException(this, "%s can not be null or empty", AES_KEY));
         String digestAlgorithm = props.getProperty(DIGEST_ALGORITHM_NAME, 
MessageDigestAlgorithms.SHA_1);
         return 
Arrays.copyOf(DigestUtils.getDigest(digestAlgorithm.toUpperCase()).digest(aesKey.getBytes(StandardCharsets.UTF_8)),
 16);
     }
diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
index 839dce5326f..2cb1266427e 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.encrypt.checker;
 
-import com.google.common.base.Strings;
 import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
@@ -70,9 +69,9 @@ public final class EncryptRuleConfigurationChecker implements 
RuleConfigurationC
     
     private void checkCipherColumn(final String databaseName, final String 
tableName, final String logicColumnName,
                                    final EncryptColumnItemRuleConfiguration 
cipherColumnConfig, final Map<String, AlgorithmConfiguration> encryptors) {
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(cipherColumnConfig.getName()),
+        ShardingSpherePreconditions.checkNotEmpty(cipherColumnConfig.getName(),
                 () -> new MissingRequiredEncryptColumnException("Cipher", new 
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(cipherColumnConfig.getEncryptorName()),
+        
ShardingSpherePreconditions.checkNotEmpty(cipherColumnConfig.getEncryptorName(),
                 () -> new EmptyAlgorithmException("Standard encrypt", new 
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
         
ShardingSpherePreconditions.checkState(encryptors.containsKey(cipherColumnConfig.getEncryptorName()),
                 () -> new UnregisteredAlgorithmException("Standard encrypt", 
cipherColumnConfig.getEncryptorName(), new SQLExceptionIdentifier(databaseName, 
tableName, logicColumnName)));
@@ -80,9 +79,9 @@ public final class EncryptRuleConfigurationChecker implements 
RuleConfigurationC
     
     private void checkAssistColumn(final String databaseName, final String 
tableName, final String logicColumnName,
                                    final EncryptColumnItemRuleConfiguration 
assistedQueryColumnConfig, final Map<String, AlgorithmConfiguration> 
encryptors) {
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(assistedQueryColumnConfig.getName()),
+        
ShardingSpherePreconditions.checkNotEmpty(assistedQueryColumnConfig.getName(),
                 () -> new MissingRequiredEncryptColumnException("Assisted 
query", new SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(assistedQueryColumnConfig.getEncryptorName()),
+        
ShardingSpherePreconditions.checkNotEmpty(assistedQueryColumnConfig.getEncryptorName(),
                 () -> new EmptyAlgorithmException("Assist query encrypt", new 
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
         
ShardingSpherePreconditions.checkState(encryptors.containsKey(assistedQueryColumnConfig.getEncryptorName()),
                 () -> new UnregisteredAlgorithmException("Assist query 
encrypt", assistedQueryColumnConfig.getEncryptorName(), new 
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
@@ -90,9 +89,9 @@ public final class EncryptRuleConfigurationChecker implements 
RuleConfigurationC
     
     private void checkLikeColumn(final String databaseName, final String 
tableName, final String logicColumnName,
                                  final EncryptColumnItemRuleConfiguration 
likeQueryColumnConfig, final Map<String, AlgorithmConfiguration> encryptors) {
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(likeQueryColumnConfig.getName()),
+        
ShardingSpherePreconditions.checkNotEmpty(likeQueryColumnConfig.getName(),
                 () -> new MissingRequiredEncryptColumnException("Like", new 
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(likeQueryColumnConfig.getEncryptorName()),
+        
ShardingSpherePreconditions.checkNotEmpty(likeQueryColumnConfig.getEncryptorName(),
                 () -> new EmptyAlgorithmException("Like query", new 
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
         
ShardingSpherePreconditions.checkState(encryptors.containsKey(likeQueryColumnConfig.getEncryptorName()),
                 () -> new UnregisteredAlgorithmException("Like query encrypt", 
likeQueryColumnConfig.getEncryptorName(), new 
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingDataSourceRuleConfigurationChecker.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingDataSourceRuleConfigurationChecker.java
index 94e8ef249f8..24be73fde69 100644
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingDataSourceRuleConfigurationChecker.java
+++ 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingDataSourceRuleConfigurationChecker.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.readwritesplitting.checker;
 
-import com.google.common.base.Strings;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -62,8 +61,8 @@ public final class 
ReadwriteSplittingDataSourceRuleConfigurationChecker {
      * @param builtRules built rules
      */
     public void check(final Collection<String> builtWriteDataSourceNames, 
final Collection<String> builtReadDataSourceNames, final 
Collection<ShardingSphereRule> builtRules) {
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(config.getName()),
 () -> new 
MissingRequiredReadwriteSplittingDataSourceRuleNameException(databaseName));
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(config.getWriteDataSourceName()),
+        ShardingSpherePreconditions.checkNotEmpty(config.getName(), () -> new 
MissingRequiredReadwriteSplittingDataSourceRuleNameException(databaseName));
+        
ShardingSpherePreconditions.checkNotEmpty(config.getWriteDataSourceName(),
                 () -> new 
MissingRequiredReadwriteSplittingActualDataSourceException(ReadwriteSplittingDataSourceType.WRITE,
 exceptionIdentifier));
         
ShardingSpherePreconditions.checkState(!config.getReadDataSourceNames().isEmpty(),
                 () -> new 
MissingRequiredReadwriteSplittingActualDataSourceException(ReadwriteSplittingDataSourceType.READ,
 exceptionIdentifier));
diff --git 
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
 
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
index 16307f27e1a..3bf159eeab0 100644
--- 
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
+++ 
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.shadow.distsql.handler.update;
 
-import com.google.common.base.Strings;
 import lombok.Setter;
 import 
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.database.DatabaseRuleAlterExecutor;
 import 
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
@@ -64,7 +63,7 @@ public final class AlterDefaultShadowAlgorithmExecutor 
implements DatabaseRuleAl
     }
     
     private void checkAlgorithmCompleteness(final AlgorithmSegment 
algorithmSegment) {
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(algorithmSegment.getName()),
 () -> new EmptyAlgorithmException("Shadow", new SQLExceptionIdentifier("")));
+        ShardingSpherePreconditions.checkNotEmpty(algorithmSegment.getName(), 
() -> new EmptyAlgorithmException("Shadow", new SQLExceptionIdentifier("")));
     }
     
     private void checkAlgorithmType(final AlgorithmSegment algorithmSegment) {
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithm.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithm.java
index a7c0328f962..465d22dc735 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithm.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithm.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.sharding.algorithm.sharding.classbased;
 
-import com.google.common.base.Strings;
 import 
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.sharding.api.sharding.complex.ComplexKeysShardingAlgorithm;
@@ -61,7 +60,7 @@ public final class ClassBasedShardingAlgorithm implements 
StandardShardingAlgori
     
     private ClassBasedShardingAlgorithmStrategyType getStrategy(final 
Properties props) {
         String strategy = props.getProperty(STRATEGY_KEY);
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(strategy),
+        ShardingSpherePreconditions.checkNotEmpty(strategy,
                 () -> new AlgorithmInitializationException(this, "Properties 
`%s` can not be null or empty when uses class based sharding strategy", 
STRATEGY_KEY));
         String shardingAlgorithmStrategyType = strategy.toUpperCase().trim();
         ShardingSpherePreconditions.checkState(
@@ -72,7 +71,7 @@ public final class ClassBasedShardingAlgorithm implements 
StandardShardingAlgori
     
     private String getAlgorithmClassName(final Properties props) {
         String result = props.getProperty(ALGORITHM_CLASS_NAME_KEY);
-        ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(result), 
() -> new AlgorithmInitializationException(this, "Sharding algorithm class name 
can not be null or empty"));
+        ShardingSpherePreconditions.checkNotEmpty(result, () -> new 
AlgorithmInitializationException(this, "Sharding algorithm class name can not 
be null or empty"));
         return result;
     }
     
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
index 2d2c6e49806..c92ba0d0530 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.sharding.algorithm.sharding.datetime;
 
-import com.google.common.base.Strings;
 import com.google.common.collect.BoundType;
 import com.google.common.collect.Range;
 import 
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
@@ -120,8 +119,7 @@ public final class IntervalShardingAlgorithm implements 
StandardShardingAlgorith
     
     private DateTimeFormatter getTableSuffixPattern(final Properties props) {
         String suffix = props.getProperty(SHARDING_SUFFIX_FORMAT_KEY);
-        ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(suffix),
-                () -> new AlgorithmInitializationException(this, 
String.format("%s can not be null or empty.", SHARDING_SUFFIX_FORMAT_KEY)));
+        ShardingSpherePreconditions.checkNotEmpty(suffix, () -> new 
AlgorithmInitializationException(this, String.format("%s can not be null or 
empty.", SHARDING_SUFFIX_FORMAT_KEY)));
         return DateTimeFormatter.ofPattern(suffix);
     }
     
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/ComplexInlineShardingAlgorithm.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/ComplexInlineShardingAlgorithm.java
index fb0257b2634..f2dd0e5a1f0 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/ComplexInlineShardingAlgorithm.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/ComplexInlineShardingAlgorithm.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.sharding.algorithm.sharding.inline;
 
-import com.google.common.base.Strings;
 import 
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException;
@@ -63,7 +62,7 @@ public final class ComplexInlineShardingAlgorithm implements 
ComplexKeysSharding
     
     private String getAlgorithmExpression(final Properties props) {
         String algorithmExpression = 
props.getProperty(ALGORITHM_EXPRESSION_KEY);
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(algorithmExpression),
 () -> new AlgorithmInitializationException(this, "Inline sharding algorithm 
expression can not be null."));
+        ShardingSpherePreconditions.checkNotEmpty(algorithmExpression, () -> 
new AlgorithmInitializationException(this, "Inline sharding algorithm 
expression can not be null."));
         return 
InlineExpressionParserFactory.newInstance(algorithmExpression.trim()).handlePlaceHolder();
     }
     
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
index 82a08b55916..cffd8228553 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.sharding.algorithm.sharding.inline;
 
-import com.google.common.base.Strings;
 import groovy.lang.MissingMethodException;
 import 
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
@@ -56,7 +55,7 @@ public final class InlineShardingAlgorithm implements 
StandardShardingAlgorithm<
     
     private String getAlgorithmExpression(final Properties props) {
         String expression = props.getProperty(ALGORITHM_EXPRESSION_KEY);
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(expression), () 
-> new AlgorithmInitializationException(this, "Inline sharding algorithm 
expression cannot be null or empty"));
+        ShardingSpherePreconditions.checkNotEmpty(expression, () -> new 
AlgorithmInitializationException(this, "Inline sharding algorithm expression 
cannot be null or empty"));
         return 
InlineExpressionParserFactory.newInstance(expression.trim()).handlePlaceHolder();
     }
     
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java
index f60581b9a09..21675c0d4e0 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.sharding.checker;
 
 import com.google.common.base.Joiner;
-import com.google.common.base.Strings;
 import 
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
 import 
org.apache.shardingsphere.infra.algorithm.core.exception.UnregisteredAlgorithmException;
 import 
org.apache.shardingsphere.infra.algorithm.keygen.core.KeyGenerateAlgorithm;
@@ -94,14 +93,14 @@ public final class ShardingRuleConfigurationChecker 
implements RuleConfiguration
     }
     
     private void checkLogicTable(final String databaseName, final String 
logicTable) {
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(logicTable), () 
-> new MissingRequiredShardingConfigurationException("Sharding logic table", 
databaseName));
+        ShardingSpherePreconditions.checkNotEmpty(logicTable, () -> new 
MissingRequiredShardingConfigurationException("Sharding logic table", 
databaseName));
     }
     
     private void checkKeyGenerateStrategy(final String databaseName, final 
KeyGenerateStrategyConfiguration keyGenerateStrategy, final Collection<String> 
keyGenerators) {
         if (null == keyGenerateStrategy) {
             return;
         }
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(keyGenerateStrategy.getColumn()),
 () -> new MissingRequiredShardingConfigurationException("Key generate column", 
databaseName));
+        
ShardingSpherePreconditions.checkNotEmpty(keyGenerateStrategy.getColumn(), () 
-> new MissingRequiredShardingConfigurationException("Key generate column", 
databaseName));
         
ShardingSpherePreconditions.checkState(keyGenerators.contains(keyGenerateStrategy.getKeyGeneratorName()),
                 () -> new UnregisteredAlgorithmException("Key generate", 
keyGenerateStrategy.getKeyGeneratorName(), new 
SQLExceptionIdentifier(databaseName)));
     }
@@ -119,7 +118,7 @@ public final class ShardingRuleConfigurationChecker 
implements RuleConfiguration
             return;
         }
         if (shardingStrategy instanceof ComplexShardingStrategyConfiguration) {
-            
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(((ComplexShardingStrategyConfiguration)
 shardingStrategy).getShardingColumns()),
+            
ShardingSpherePreconditions.checkNotEmpty(((ComplexShardingStrategyConfiguration)
 shardingStrategy).getShardingColumns(),
                     () -> new 
MissingRequiredShardingConfigurationException("Complex sharding columns", 
databaseName));
         }
         
ShardingSpherePreconditions.checkNotNull(shardingStrategy.getShardingAlgorithmName(),
 () -> new MissingRequiredShardingConfigurationException("Sharding algorithm 
name", databaseName));
diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java
index 633dd047bdc..3e8e98b84e4 100644
--- 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.infra.exception.core;
 
+import com.google.common.base.Strings;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 
@@ -55,4 +56,18 @@ public final class ShardingSpherePreconditions {
             throw exceptionSupplierIfUnexpected.get();
         }
     }
+    
+    /**
+     * Ensures that a string passed as a parameter to the calling method is 
not empty.
+     *
+     * @param <T> type of exception
+     * @param value string to be checked
+     * @param exceptionSupplierIfUnexpected exception from this supplier will 
be thrown if expression is unexpected
+     * @throws T exception to be thrown
+     */
+    public static <T extends Throwable> void checkNotEmpty(final String value, 
final Supplier<T> exceptionSupplierIfUnexpected) throws T {
+        if (Strings.isNullOrEmpty(value)) {
+            throw exceptionSupplierIfUnexpected.get();
+        }
+    }
 }
diff --git 
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java
 
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java
index 977f71f7ef5..fa49dff8447 100644
--- 
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java
+++ 
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java
@@ -44,4 +44,15 @@ class ShardingSpherePreconditionsTest {
     void assertCheckNotNullToNotThrowException() throws SQLException {
         ShardingSpherePreconditions.checkNotNull(new Object(), 
SQLException::new);
     }
+    
+    @Test
+    void assertCheckNotEmptyToThrowsException() {
+        assertThrows(SQLException.class, () -> 
ShardingSpherePreconditions.checkNotEmpty(null, SQLException::new));
+        assertThrows(SQLException.class, () -> 
ShardingSpherePreconditions.checkNotEmpty("", SQLException::new));
+    }
+    
+    @Test
+    void assertCheckNotEmptyToNotThrowException() throws SQLException {
+        ShardingSpherePreconditions.checkNotEmpty("foo", SQLException::new);
+    }
 }
diff --git 
a/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java
 
b/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java
index 50a4f92fd50..976612ce9dc 100644
--- 
a/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java
+++ 
b/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java
@@ -138,8 +138,7 @@ public class IntervalInlineExpressionParser implements 
InlineExpressionParser {
     
     private DateTimeFormatter getSuffixPattern(final Map<String, String> 
props) {
         String suffix = props.get(SUFFIX_PATTERN_KEY);
-        ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(suffix),
-                () -> new RuntimeException(String.format("%s can not be null 
or empty.", SUFFIX_PATTERN_KEY)));
+        ShardingSpherePreconditions.checkNotEmpty(suffix, () -> new 
RuntimeException(String.format("%s can not be null or empty.", 
SUFFIX_PATTERN_KEY)));
         Chronology chronology = getChronology(props);
         return DateTimeFormatter.ofPattern(suffix).withChronology(chronology);
     }
diff --git 
a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java
 
b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java
index 8c12a171915..5c7bc31229f 100644
--- 
a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java
+++ 
b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java
@@ -19,7 +19,6 @@ package 
org.apache.shardingsphere.traffic.algorithm.traffic.segment;
 
 import com.google.common.base.CharMatcher;
 import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
 import 
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
@@ -45,7 +44,7 @@ public final class SQLMatchTrafficAlgorithm implements 
SegmentTrafficAlgorithm {
     public void init(final Properties props) {
         
ShardingSpherePreconditions.checkState(props.containsKey(SQL_PROPS_KEY), () -> 
new AlgorithmInitializationException(this, "%s cannot be null", SQL_PROPS_KEY));
         sql = getExactlySQL(props.getProperty(SQL_PROPS_KEY));
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(String.valueOf(sql)),
 () -> new AlgorithmInitializationException(this, "SQL must be not empty"));
+        ShardingSpherePreconditions.checkNotEmpty(String.valueOf(sql), () -> 
new AlgorithmInitializationException(this, "SQL must be not empty"));
     }
     
     private Collection<String> getExactlySQL(final String value) {
diff --git 
a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java
 
b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java
index f2a4327263f..2a4631e1081 100644
--- 
a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java
+++ 
b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.traffic.algorithm.traffic.segment;
 
-import com.google.common.base.Strings;
 import 
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.traffic.api.traffic.segment.SegmentTrafficAlgorithm;
@@ -39,7 +38,7 @@ public final class SQLRegexTrafficAlgorithm implements 
SegmentTrafficAlgorithm {
     public void init(final Properties props) {
         
ShardingSpherePreconditions.checkState(props.containsKey(REGEX_PROPS_KEY), () 
-> new AlgorithmInitializationException(this, "%s cannot be null", 
REGEX_PROPS_KEY));
         regex = Pattern.compile(props.getProperty(REGEX_PROPS_KEY));
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(String.valueOf(regex)),
 () -> new AlgorithmInitializationException(this, "Regex must be not empty"));
+        ShardingSpherePreconditions.checkNotEmpty(String.valueOf(regex), () -> 
new AlgorithmInitializationException(this, "Regex must be not empty"));
     }
     
     @Override
diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
index 699054e8be5..7c845221da0 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.mode.manager;
 
-import com.google.common.base.Strings;
 import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
@@ -109,7 +108,7 @@ public final class ContextManager implements AutoCloseable {
      * @return got database
      */
     public ShardingSphereDatabase getDatabase(final String name) {
-        ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(name), 
NoDatabaseSelectedException::new);
+        ShardingSpherePreconditions.checkNotEmpty(name, 
NoDatabaseSelectedException::new);
         ShardingSphereMetaData metaData = getMetaDataContexts().getMetaData();
         
ShardingSpherePreconditions.checkState(metaData.containsDatabase(name), () -> 
new UnknownDatabaseException(name));
         return metaData.getDatabase(name);
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
index 841f1eaa5ec..b88cbd75b5f 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/YamlDatabaseConfigurationImportExecutor.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.proxy.backend.util;
 
-import com.google.common.base.Strings;
 import 
org.apache.shardingsphere.distsql.handler.validate.DistSQLDataSourcePoolPropertiesValidator;
 import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
 import 
org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationCheckEngine;
@@ -92,7 +91,7 @@ public final class YamlDatabaseConfigurationImportExecutor {
     }
     
     private void checkDatabase(final String databaseName) {
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(databaseName), 
MissingRequiredDatabaseException::new);
+        ShardingSpherePreconditions.checkNotEmpty(databaseName, 
MissingRequiredDatabaseException::new);
         
ShardingSpherePreconditions.checkState(!ProxyContext.getInstance().databaseExists(databaseName),
 () -> new DatabaseCreateExistsException(databaseName));
     }
     
diff --git 
a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
 
b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
index 8506fcda462..af2bb86c306 100644
--- 
a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
+++ 
b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
@@ -155,7 +155,7 @@ public final class OpenGaussAuthenticationEngine implements 
AuthenticationEngine
         clientEncoding = startupPacket.getClientEncoding();
         
context.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(PostgreSQLCharacterSets.findCharacterSet(clientEncoding));
         String username = startupPacket.getUsername();
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(username), 
EmptyUsernameException::new);
+        ShardingSpherePreconditions.checkNotEmpty(username, 
EmptyUsernameException::new);
         context.writeAndFlush(getIdentifierPacket(username, rule, 
startupPacket.getVersion()));
         currentAuthResult = AuthenticationResultBuilder.continued(username, 
"", startupPacket.getDatabase());
         return currentAuthResult;
diff --git 
a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
 
b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
index f94a62f1375..d09c731fa41 100644
--- 
a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
+++ 
b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
@@ -136,7 +136,7 @@ public final class PostgreSQLAuthenticationEngine 
implements AuthenticationEngin
         clientEncoding = startupPacket.getClientEncoding();
         
context.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(PostgreSQLCharacterSets.findCharacterSet(clientEncoding));
         String username = startupPacket.getUsername();
-        
ShardingSpherePreconditions.checkState(!Strings.isNullOrEmpty(username), 
EmptyUsernameException::new);
+        ShardingSpherePreconditions.checkNotEmpty(username, 
EmptyUsernameException::new);
         context.writeAndFlush(getIdentifierPacket(username, rule));
         currentAuthResult = AuthenticationResultBuilder.continued(username, 
"", startupPacket.getDatabase());
         return currentAuthResult;


Reply via email to