AmarGhugare opened a new pull request, #1865:
URL: https://github.com/apache/commons-lang/pull/1865

   `Fraction.divideBy()` throws an overflow exception for representable 
quotients when the divisor has an `Integer.MIN_VALUE` numerator. For example:
   
   ```java
   Fraction value = Fraction.getFraction(Integer.MIN_VALUE, 1);
   value.divideBy(value);          // Expected: 1/1. Currently throws 
ArithmeticException.
   Fraction.ZERO.divideBy(value);  // Expected: 0/1. Currently throws 
ArithmeticException.
   ```
   
   The method calls `invert()` before multiplying, so it tries to construct a 
reciprocal with a positive denominator of `2147483648` before common factors 
can be cancelled.
   
   Compute the quotient numerator and denominator as `long` products, normalize 
the sign, reduce using Euclid's algorithm, and narrow the final values with 
`Math.toIntExact`. Products of two `int` values fit in a `long`, allowing 
reduction before the final range checks. Zero dividends return the canonical 
`ZERO` instance after validating the divisor. Null divisors, division by zero, 
and unrepresentable final results still throw. The standalone `invert()` method 
is unchanged.
   
   Added 19 regression test invocations covering minimum-value operands, 
reduced and unreduced fractions, signs, zero dividends, and genuine 
numerator/denominator overflow. Ten of these invocations fail against the 
original implementation.
   
   Validation:
   
   - All 58 `FractionTest` invocations pass.
   - Full default Maven build passes on JDK 25 with Java 8 compilation target: 
108,501 tests, zero failures or errors, 18 skipped. Coverage, RAT, Checkstyle, 
Japicmp, SpotBugs, PMD, and Javadoc checks pass.
   - An additional standalone local check compared 5,929 boundary divisions 
with exact `BigInteger` results, including expected overflow and zero-divisor 
exceptions; all matched.
   - `git diff --check` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to