Pace2Car commented on code in PR #25246:
URL: https://github.com/apache/shardingsphere/pull/25246#discussion_r1174528654


##########
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithm.java:
##########
@@ -60,14 +60,19 @@ public void init(final Properties props) {
     private ClassBasedShardingAlgorithmStrategyType getStrategy(final 
Properties props) {
         String strategy = props.getProperty(STRATEGY_KEY);
         ShardingSpherePreconditions.checkNotNull(strategy,
-                () -> new ShardingAlgorithmInitializationException(getType(), 
String.format("Properties `%s` can not be null when uses class based sharding 
strategy.", STRATEGY_KEY)));
-        return 
ClassBasedShardingAlgorithmStrategyType.valueOf(strategy.toUpperCase().trim());
+                () -> new ShardingAlgorithmInitializationException(getType(), 
String.format("Properties `%s` can not be null when uses class based sharding 
strategy", STRATEGY_KEY)));
+        String shardingAlgorithmStrategyType = strategy.toUpperCase().trim();
+        ShardingSpherePreconditions.checkState(
+                
ClassBasedShardingAlgorithmStrategyType.isValidShardingAlgorithmStrategyType(shardingAlgorithmStrategyType),
+                () -> new ShardingAlgorithmInitializationException(getType(), 
String.format("Sharding strategy `%s` not support", strategy)));
+        return 
ClassBasedShardingAlgorithmStrategyType.valueOf(shardingAlgorithmStrategyType);
     }
-    
+
     private String getAlgorithmClassName(final Properties props) {
         String result = props.getProperty(ALGORITHM_CLASS_NAME_KEY);
         ShardingSpherePreconditions.checkNotNull(result,
-                () -> new ShardingAlgorithmInitializationException(getType(), 
String.format("Properties `%s` can not be null when uses class based sharding 
strategy.", ALGORITHM_CLASS_NAME_KEY)));
+                () -> new ShardingAlgorithmInitializationException(getType(), 
String.format("Properties `%s` can not be null when uses class based sharding 
strategy", ALGORITHM_CLASS_NAME_KEY)));
+        ShardingSpherePreconditions.checkState(!"".equals(result), () -> new 
ShardingAlgorithmInitializationException(getType(), "Sharding algorithm 
ClassName can not be a empty string"));

Review Comment:
   These two checks can be combined into `!Strings.isNullOrEmpty(result)`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to