You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/11/29 01:32:46 UTC

[GitHub] [shardingsphere-elasticjob] TeslaCN commented on a diff in pull request #2151: Bug: Bad attempt to compute absolute value of signed 32-bit hashcode

TeslaCN commented on code in PR #2151:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/2151#discussion_r1034212910


##########
elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/handler/sharding/impl/RoundRobinByNameJobShardingStrategy.java:
##########
@@ -38,7 +38,13 @@ public Map<JobInstance, List<Integer>> sharding(final List<JobInstance> jobInsta
     
     private List<JobInstance> rotateServerList(final List<JobInstance> shardingUnits, final String jobName) {
         int shardingUnitsSize = shardingUnits.size();
-        int offset = Math.abs(jobName.hashCode()) % shardingUnitsSize;
+        int jobHashCode = jobName.hashCode();
+        int offset = 0;
+        if (jobHashCode != Integer.MIN_VALUE) {
+            offset = Math.abs(jobHashCode) % shardingUnitsSize;
+        } else {
+            offset = Integer.MIN_VALUE % shardingUnitsSize;
+        }

Review Comment:
   Hi @zume0127 
   Could you complete the tests `org.apache.shardingsphere.elasticjob.infra.handler.sharding.impl.RotateServerByNameJobShardingStrategyTest` for your logic?



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org