diff --git a/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/MathUtils.scala b/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/MathUtils.scala index d0e36a83f9d..31f3c9583be 100644 --- a/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/MathUtils.scala +++ b/kyuubi-util-scala/src/main/scala/org/apache/kyuubi/util/MathUtils.scala @@ -21,30 +21,40 @@ object MathUtils { /** * Check if the given object represents a positive number in value */ - def isPositiveNumber(o: Any): Boolean = o match { - case intValue: Int => intValue > 0 - case longValue: Long => longValue > 0L - case floatValue: Float => floatValue > 0.0f - case doubleValue: Double => doubleValue > 0.0d - case byteValue: Byte => byteValue > 0 - case shortValue: Short => shortValue > 0 - case charValue: Char => charValue > 0 - case stringValue: String => stringValue.toDouble >= 0.0d - case _ => throw new IllegalArgumentException(s"Cannot check if $o is a positive number.") - } + def isPositiveNumber(o: Any): Boolean = + try { + o match { + case intValue: Int => intValue > 0 + case longValue: Long => longValue > 0L + case floatValue: Float => floatValue > 0.0f + case doubleValue: Double => doubleValue > 0.0d + case byteValue: Byte => byteValue > 0 + case shortValue: Short => shortValue > 0 + case charValue: Char => charValue > 0 + case stringValue: String => stringValue.toDouble >= 0.0d + } + } catch { + case t: Throwable => + throw new IllegalArgumentException(s"Cannot check if $o is a positive number.", t) + } /** * Check if the given object represents a non-negative number in value */ - def isNonNegativeNumber(o: Any): Boolean = o match { - case intValue: Int => intValue >= 0 - case longValue: Long => longValue >= 0L - case floatValue: Float => floatValue >= 0.0f - case doubleValue: Double => doubleValue >= 0.0d - case byteValue: Byte => byteValue >= 0 - case shortValue: Short => shortValue >= 0 - case charValue: Char => charValue >= 0 - case stringValue: String => stringValue.toDouble >= 0.0d - case _ => throw new IllegalArgumentException(s"Cannot check if $o is a non-negative number.") - } + def isNonNegativeNumber(o: Any): Boolean = + try { + o match { + case intValue: Int => intValue >= 0 + case longValue: Long => longValue >= 0L + case floatValue: Float => floatValue >= 0.0f + case doubleValue: Double => doubleValue >= 0.0d + case byteValue: Byte => byteValue >= 0 + case shortValue: Short => shortValue >= 0 + case charValue: Char => charValue >= 0 + case stringValue: String => stringValue.toDouble >= 0.0d + } + } catch { + case t: Throwable => + throw new IllegalArgumentException(s"Cannot check if $o is a non-negative number.", t) + } }