fix[net]: fixed the inconsistency between the hashcode and int Value() return values of the Long wrapper class

This commit is contained in:
godotg committed 2022-12-12 09:08:35 +08:00
1 parent a68ef4eb28
commit 04ff16027f
1 file changed
+11 -3
@@ -114,11 +114,11 @@ public final class TaskBus {
if (attachment == null) { if (attachment == null) {
var session = task.getSession(); var session = task.getSession();
var uid = session.getAttribute(AttributeType.UID); var uid = (Long) session.getAttribute(AttributeType.UID);
if (uid == null) { if (uid == null) {
execute((int) session.getSid(), task); execute((int) session.getSid(), task);
} else { } else {
execute((int) uid, task); execute(uid.intValue(), task);
} }
} else { } else {
execute(attachment.taskExecutorHash(), task); execute(attachment.taskExecutorHash(), task);
@@ -131,7 +131,15 @@ public final class TaskBus {
} }
public static int calTaskExecutorHash(Object argument) { public static int calTaskExecutorHash(Object argument) {
return calTaskExecutorHash((argument == null) ? RandomUtils.randomInt() : argument.hashCode()); var hash = 0;
if (argument == null) {
hash = RandomUtils.randomInt();
} else if (argument instanceof Number) {
hash = ((Number) argument).intValue();
} else {
hash = argument.hashCode();
}
return calTaskExecutorHash(hash);
} }
public static void execute(int taskExecutorHash, Runnable runnable) { public static void execute(int taskExecutorHash, Runnable runnable) {