andreachild commented on code in PR #3153:
URL: https://github.com/apache/tinkerpop/pull/3153#discussion_r2241309967
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/NumberHelper.java:
##########
@@ -717,8 +764,30 @@ public static Number coerceTo(final Number a, final
Class<? extends Number> claz
throw new IllegalArgumentException("Unsupported numeric type: " +
clazz);
}
- // return as-is since it didn't fit the type we wanted to coerce to
- return a;
+ throw new ArithmeticException(String.format("Can't convert number of
type %s to %s due to overflow.",
+ a.getClass().getSimpleName(), clazz.getSimpleName()));
+ }
+
+ private static Long getLong(final Number num, final Class<? extends
Number> clazz) {
+ // Explicitly throw when converting floating point infinity and NaN to
whole numbers
+ if (Double.isNaN(num.doubleValue())) {
+ throw new ArithmeticException(String.format("Can't convert NaN to
%s.", clazz.getSimpleName()));
+ }
+ if (Double.isInfinite(num.doubleValue())) {
+ throw new ArithmeticException(String.format("Can't convert
floating point infinity to %s.", clazz.getSimpleName()));
+ }
+ String msg = String.format("Can't convert number of type %s to %s due
to overflow.",
+ num.getClass().getSimpleName(), clazz.getSimpleName());
+ if ((num.getClass().equals(Double.class) ||
num.getClass().equals(Float.class)) && (num.doubleValue()) > Long.MAX_VALUE) {
Review Comment:
Do we also need to check for underflow?
--
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]