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

morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new aba9d6a3d40 branch-3.1: [bugfix](catalog) replace Math.abs with 
bitwise AND to ensure non-negative ID generation #55183 (#55689)
aba9d6a3d40 is described below

commit aba9d6a3d40dd3b2bc95bfe07cf4c74a0943afb6
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sat Sep 6 00:39:21 2025 +0800

    branch-3.1: [bugfix](catalog) replace Math.abs with bitwise AND to ensure 
non-negative ID generation #55183 (#55689)
    
    Cherry-picked from #55183
    
    Co-authored-by: lw112 <[email protected]>
---
 .../src/main/java/org/apache/doris/common/util/Util.java     |  7 ++++++-
 .../src/test/java/org/apache/doris/common/util/UtilTest.java | 12 ++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java 
b/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java
index ab14b529441..3b96e7b3b54 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java
@@ -714,7 +714,12 @@ public class Util {
             MessageDigest digest = MessageDigest.getInstance("SHA-256");
             byte[] hash = digest.digest(str.getBytes(StandardCharsets.UTF_8));
             ByteBuffer buffer = ByteBuffer.wrap(hash);
-            return buffer.getLong();
+            long result = buffer.getLong();
+            // Handle Long.MIN_VALUE case to ensure non-negative ID generation
+            if (result == Long.MIN_VALUE) {
+                return str.hashCode();
+            }
+            return result;
         } catch (NoSuchAlgorithmException e) {
             return str.hashCode();
         }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/common/util/UtilTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/common/util/UtilTest.java
index dc8419ddd1f..88403effa31 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/common/util/UtilTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/common/util/UtilTest.java
@@ -90,4 +90,16 @@ public class UtilTest {
         String str1 = "东方卫视";
         Assertions.assertNotEquals(Util.sha256long(str), 
Util.sha256long(str1));
     }
+
+    @Test
+    public void sha256longHandlesLongMinValue() {
+        String testStr = "test_long_min_value_case";
+        long result = Util.sha256long(testStr);
+
+        Assertions.assertNotEquals(Long.MIN_VALUE, result,
+                "sha256long should not return Long.MIN_VALUE");
+
+        Assertions.assertEquals(result, Util.sha256long(testStr),
+                "Same input should produce same output");
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to