[FLINK-4594] [core] Validate lower bound in MathUtils.checkedDownCast This closes #2481
Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/4f84a02f Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/4f84a02f Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/4f84a02f Branch: refs/heads/flip-6 Commit: 4f84a02f4b8be5948b233531fbcb07dfdb5e7930 Parents: 470b752 Author: Greg Hogan <c...@greghogan.com> Authored: Thu Sep 8 10:35:39 2016 -0400 Committer: Greg Hogan <c...@greghogan.com> Committed: Tue Sep 20 10:10:20 2016 -0400 ---------------------------------------------------------------------- flink-core/src/main/java/org/apache/flink/util/MathUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flink/blob/4f84a02f/flink-core/src/main/java/org/apache/flink/util/MathUtils.java ---------------------------------------------------------------------- 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 49056cc..074e8ae 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 final class MathUtils { * * @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; } /**