-
Notifications
You must be signed in to change notification settings - Fork 0
KAFAK-14604: SASL session expiration time will be overflowed when calculation #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1697,4 +1697,17 @@ public static ConfigDef mergeConfigs(List<ConfigDef> configDefs) { | |||||||||||||||||||||||||||
public interface ThrowingRunnable { | ||||||||||||||||||||||||||||
void run() throws Exception; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* convert millisecond to nanosecond, or throw exception if overflow | ||||||||||||||||||||||||||||
* @param timeMs the time in millisecond | ||||||||||||||||||||||||||||
* @return the converted nanosecond | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
public static long msToNs(long timeMs) { | ||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||
return Math.multiplyExact(1000 * 1000, timeMs); | ||||||||||||||||||||||||||||
} catch (ArithmeticException e) { | ||||||||||||||||||||||||||||
throw new IllegalArgumentException("Cannot convert " + timeMs + " millisecond to nanosecond due to arithmetic overflow", e); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+1706
to
+1711
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1109,6 +1109,13 @@ public void testTryAll() throws Throwable { | |
assertEquals(expected, recorded); | ||
} | ||
|
||
@Test | ||
public void testMsToNs() { | ||
assertEquals(1000000, Utils.msToNs(1)); | ||
assertEquals(0, Utils.msToNs(0)); | ||
assertThrows(IllegalArgumentException.class, () -> Utils.msToNs(Long.MAX_VALUE)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case verifies that an assertThrows(IllegalArgumentException.class, () -> Utils.msToNs(Long.MAX_VALUE));
assertThrows(IllegalArgumentException.class, () -> Utils.msToNs(Long.MAX_VALUE - 1));
assertThrows(IllegalArgumentException.class, () -> Utils.msToNs(Long.MAX_VALUE / 2)); |
||
} | ||
|
||
private Callable<Void> recordingCallable(Map<String, Object> recordingMap, String success, TestException failure) { | ||
return () -> { | ||
if (success == null) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the change in
SaslClientAuthenticator.java
, this change usesMath.addExact
andUtils.msToNs
to prevent potential overflow. This is consistent and correct.