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


##########
clients/src/test/java/org/apache/kafka/common/security/authenticator/SaslServerAuthenticatorTest.java:
##########
@@ -243,6 +243,40 @@ public void testSessionExpiresAtTokenExpiry() throws 
IOException {
         }
     }
 
+    @Test
+    public void testSessionWontExpiresWithLargeExpirationTime() throws 
IOException {

Review Comment:
   ```suggestion
       public void testSessionWontExpireWithLargeExpirationTime() throws 
IOException {
   ```



##########
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

Review Comment:
   Any reason for this not to be a Javadoc?



##########
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) {
+        long result = Long.MAX_VALUE;
+        try {
+            result = Math.addExact(a, b);
+        } catch (ArithmeticException e) {
+            log.info("The sum of {} and {} is overflowed, set to 
Long.MAX_VALUE", a, b);

Review Comment:
   I think this needs more context: If this gets logged how it the reader of 
the log supposed to know what went wrong?
   
   Perhaps the way to do it is just to check whether end result of the overall 
calculation is `Long.MAX_VALUE` and log the message then. Perhaps it should be 
a `warn` too, since it indicates a configuration problem that really should be 
fixed; if so we might want to log it only once.



-- 
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-unsubscr...@kafka.apache.org

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

Reply via email to