From 900c42bcc88f301a7190e477e179a0774e918f40 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 22 Feb 2022 11:48:41 -0800 Subject: [PATCH] Add error message for Decimals utility methods --- .../src/main/java/io/trino/spi/type/Decimals.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/core/trino-spi/src/main/java/io/trino/spi/type/Decimals.java b/core/trino-spi/src/main/java/io/trino/spi/type/Decimals.java index e08b5fde040a..65bccd09a536 100644 --- a/core/trino-spi/src/main/java/io/trino/spi/type/Decimals.java +++ b/core/trino-spi/src/main/java/io/trino/spi/type/Decimals.java @@ -130,7 +130,9 @@ public static long encodeShortScaledValue(BigDecimal value, int scale) public static long encodeShortScaledValue(BigDecimal value, int scale, RoundingMode roundingMode) { - checkArgument(scale >= 0); + if (scale < 0) { + throw new IllegalArgumentException("scale is negative: " + scale); + } return value.setScale(scale, roundingMode).unscaledValue().longValueExact(); } @@ -141,7 +143,9 @@ public static Int128 encodeScaledValue(BigDecimal value, int scale) public static Int128 encodeScaledValue(BigDecimal value, int scale, RoundingMode roundingMode) { - checkArgument(scale >= 0); + if (scale < 0) { + throw new IllegalArgumentException("scale is negative: " + scale); + } return valueOf(value.setScale(scale, roundingMode)); } @@ -265,13 +269,6 @@ public static boolean isLongDecimal(Type type) return type instanceof LongDecimalType; } - private static void checkArgument(boolean condition) - { - if (!condition) { - throw new IllegalArgumentException(); - } - } - /** * Converts {@link BigDecimal} to {@link Int128} representing it for long {@link DecimalType}. * It is caller responsibility to ensure that {@code value.scale()} equals to {@link DecimalType#getScale()}.