You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2022/12/06 14:50:24 UTC
[shardingsphere-elasticjob] branch master updated: Bug: Bad attempt to compute absolute value of signed 32-bit hashcode (#2151)
This is an automated email from the ASF dual-hosted git repository.
wuweijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git
The following commit(s) were added to refs/heads/master by this push:
new 3fb749a4e Bug: Bad attempt to compute absolute value of signed 32-bit hashcode (#2151)
3fb749a4e is described below
commit 3fb749a4e40fe65c82741ca2622c052707bfa3f7
Author: zume0127 <79...@qq.com>
AuthorDate: Tue Dec 6 22:50:13 2022 +0800
Bug: Bad attempt to compute absolute value of signed 32-bit hashcode (#2151)
* Bug: Bad attempt to compute absolute value of signed 32-bit hashcode
* check code style
---
.../sharding/impl/RoundRobinByNameJobShardingStrategy.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/handler/sharding/impl/RoundRobinByNameJobShardingStrategy.java b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/handler/sharding/impl/RoundRobinByNameJobShardingStrategy.java
index a3cb679d5..dfcf93702 100644
--- a/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/handler/sharding/impl/RoundRobinByNameJobShardingStrategy.java
+++ b/elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/handler/sharding/impl/RoundRobinByNameJobShardingStrategy.java
@@ -38,7 +38,13 @@ public final class RoundRobinByNameJobShardingStrategy implements JobShardingStr
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;
+ }
if (0 == offset) {
return shardingUnits;
}