dongjoon-hyun commented on code in PR #51977:
URL: https://github.com/apache/spark/pull/51977#discussion_r2267998183
##########
common/utils/src/main/java/org/apache/spark/network/util/JavaUtils.java:
##########
@@ -656,4 +656,11 @@ public static String stackTraceToString(Throwable t) {
}
return out.toString(StandardCharsets.UTF_8);
}
+
+ public static int checkedCast(long value) {
+ if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) {
+ throw new IllegalArgumentException("Cannot cast to integer.");
Review Comment:
I tried to utilize Java's `Math.toIntExact` first but I cannot use it
because of the difference of exceptions.
```java
jshell> Math.toIntExact(Long.MAX_VALUE)
| Exception java.lang.ArithmeticException: integer overflow
| at Math.toIntExact (Math.java:1371)
| at (#1:1)
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]