LANG-1834 Fix Fraction reduction for Integer.MIN_VALUE - #1794
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The reviewed changes address the overflow case with regression coverage.
Pull request overview
Fixes Fraction.getReducedFraction handling for Integer.MIN_VALUE with negative denominators.
Changes:
- Reduces common powers of two before sign normalization.
- Adds regression tests for representable and overflowing edge cases.
File summaries
| File | Summary |
|---|---|
src/test/java/org/apache/commons/lang3/math/FractionTest.java |
Adds boundary-value regression coverage. |
src/main/java/org/apache/commons/lang3/math/Fraction.java |
Updates fraction reduction logic to avoid overflow. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Member
|
@makarandhinge Thank you, merged 🚀 |
garydgregory
added a commit
that referenced
this pull request
Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for your contribution to Apache Commons! Your help is appreciated!
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.Fix
Fraction.getReducedFractionhandling forInteger.MIN_VALUEwith a negative denominator.When the numerator is
Integer.MIN_VALUEand the denominator is negative, the current implementation can attempt to negateInteger.MIN_VALUE, which overflows and throws anArithmeticExceptioneven when the fraction can be reduced to a valid integer fraction.This change reduces common powers of two from the numerator and denominator before sign normalization, avoiding the overflow for representable fractions while preserving overflow handling for results that cannot be represented as
int.Tests
Added regression coverage for:
Integer.MIN_VALUE / -2Integer.MIN_VALUE / -6Integer.MIN_VALUE / Integer.MIN_VALUEInteger.MIN_VALUE / -1(overflow)Integer.MIN_VALUE / -3(overflow)All existing
FractionTesttests continue to pass.