From d273919155cfef48d807b7f93430b52944e145f4 Mon Sep 17 00:00:00 2001 From: Greg Hogan Date: Thu, 8 Sep 2016 10:35:39 -0400 Subject: [PATCH] [FLINK-4594] [core] Validate lower bound in MathUtils.checkedDownCast --- .../src/main/java/org/apache/flink/util/MathUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/flink-core/src/main/java/org/apache/flink/util/MathUtils.java b/flink-core/src/main/java/org/apache/flink/util/MathUtils.java index 49056ccd80f96..074e8aea66f9c 100644 --- a/flink-core/src/main/java/org/apache/flink/util/MathUtils.java +++ b/flink-core/src/main/java/org/apache/flink/util/MathUtils.java @@ -80,12 +80,14 @@ public static int roundDownToPowerOf2(int value) { * * @param value The value to be cast to an integer. * @return The given value as an integer. + * @see Math#toIntExact(long) */ public static int checkedDownCast(long value) { - if (value > Integer.MAX_VALUE) { + int downCast = (int) value; + if (downCast != value) { throw new IllegalArgumentException("Cannot downcast long value " + value + " to integer."); } - return (int) value; + return downCast; } /**