You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2023/01/10 04:52:18 UTC

[GitHub] [kafka] showuon commented on a diff in pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

showuon commented on code in PR #13099:
URL: https://github.com/apache/kafka/pull/13099#discussion_r1065331903


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1496,4 +1496,32 @@ public static String replaceSuffix(String str, String oldSuffix, String newSuffi
             throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
         return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
     }
+
+    public static long zeroIfNegative(long value) {
+        return Math.max(0L, value);
+    }
+
+    // returns the sum of a and b unless it would overflow, which will return Long.MAX_VALUE
+    public static long saturatedAdd(long a, long b) {

Review Comment:
   The method name is copied from guava's [LongMath class](https://guava.dev/releases/20.0/api/docs/com/google/common/math/LongMath.html#saturatedAdd-long-long-).



-- 
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: jira-unsubscribe@kafka.apache.org

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