You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2019/08/08 17:30:39 UTC

[commons-numbers] 16/18: NUMBERS-120: Report argument values in IllegalArgumentException messages

This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 26c9e7f0c9962ffaed9743e8584f5e2809ecabed
Author: Schamschi <he...@gmx.at>
AuthorDate: Sat Jul 13 18:53:32 2019 +0200

    NUMBERS-120: Report argument values in IllegalArgumentException messages
---
 .../java/org/apache/commons/numbers/fraction/BigFraction.java | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
index a9a50ee..f2bac32 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
@@ -671,18 +671,20 @@ public class BigFraction extends Number implements Comparable<BigFraction>, Seri
      * sign.
      * @param exponentLength the number of bits allowed for the exponent; must be
      *                       between 1 and 32 (inclusive), and must not be greater
-     *                       than 63 - significandLength
+     *                       than {@code 63 - significandLength}
      * @param significandLength the number of bits allowed for the significand
      *                          (excluding the implicit leading 1-bit in
      *                          normalized numbers, e.g. 52 for a double-precision
      *                          floating-point number); must be between 1 and
-     *                          (63 - exponentLength) (inclusive)
+     *                          {@code 63 - exponentLength} (inclusive)
      * @return the bits of an IEEE 754 binary floating-point representation of
      * this fraction encoded in a {@code long}, as described above.
+     * @throws IllegalArgumentException if the arguments do not meet the
+     *         criteria described above
      */
     private long toFloatingPointBits(int exponentLength, int significandLength) {
         if (exponentLength < 1 ||significandLength < 1 || exponentLength > Math.min(32, 63 - significandLength)) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException("exponent length: " + exponentLength + "; significand length: " + significandLength);
         }
         if (numerator.signum() == 0) {
             return 0L;
@@ -841,10 +843,11 @@ public class BigFraction extends Number implements Comparable<BigFraction>, Seri
      * @param hasFractionalBits whether the number should be treated as though
      *                          it contained a non-zero fractional part
      * @return a {@code BigInteger} as described above
+     * @throws IllegalArgumentException if {@code bits <= 0}
      */
     private static BigInteger roundAndRightShift(BigInteger value, int bits, boolean hasFractionalBits) {
         if (bits <= 0) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException("bits: " + bits);
         }
         BigInteger result = value.shiftRight(bits);
         if (value.testBit(bits - 1) &&