code: private static long checkedLongValue(Number number, Class<? extends Number> targetClass) {
          BigInteger bigInt = null;
          if (number instanceof BigInteger) {
              bigInt = (BigInteger) number;
          } else if (number instanceof BigDecimal) {
              bigInt = ((BigDecimal) number).toBigInteger();
          }
          // Effectively analogous to JDK 8's BigInteger.longValueExact()
          if (bigInt != null && (bigInt.compareTo(LONG_MIN) < 0 || bigInt.compareTo(LONG_MAX) > 0)) {
              raiseOverflowException(number, targetClass);
          }
          return number.longValue();
      }
docs: Check for a {@code BigInteger}/{@code BigDecimal} long overflow
  before returning the given number as a long value.
  @param number      the number to convert
  @param targetClass the target class to convert to
  @return the long value, if convertible without overflow
  @throws IllegalArgumentException if there is an overflow
  @see #raiseOverflowException