fix: add null input validation to AlternativeStringArrange.arrange()#7425
Merged
DenizAltunkapan merged 2 commits intoMay 18, 2026
Conversation
The arrange() method previously threw a NullPointerException when either input string was null. This change explicitly validates the inputs and throws IllegalArgumentException with a clear message, matching the fail-fast pattern used by other utility classes in this package (e.g. HammingDistance). - Add null guard at the start of arrange() - Update Javadoc with @throws and contract notes - Add parameterized test covering all three null-input combinations
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7425 +/- ##
=========================================
Coverage 79.62% 79.63%
- Complexity 7237 7241 +4
=========================================
Files 800 800
Lines 23606 23608 +2
Branches 4646 4646
=========================================
+ Hits 18797 18800 +3
- Misses 4054 4055 +1
+ Partials 755 753 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
DenizAltunkapan
approved these changes
May 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.
What
Adds explicit null-input validation to
AlternativeStringArrange.arrange().Previously, calling
arrange(null, "abc")(or with the second argument null, or both null) threw aNullPointerExceptionfrom inside the method with no useful message. After this change, it throws anIllegalArgumentExceptionwith the message"Input strings must not be null", matching the fail-fast convention already used by other utility classes in this package (for exampleHammingDistance.calculateHammingDistance).Why
@throws IllegalArgumentExceptionis now documented in the Javadoc, so callers know what to expect.NPEwith no message is hard to debug."Input strings must not be null"makes the cause obvious.HammingDistanceand other string utilities in this package.Changes
src/main/java/.../AlternativeStringArrange.javaarrange()throwingIllegalArgumentException.@throwsand a note that inputs must be non-null.src/test/java/.../AlternativeStringArrangeTest.javaarrangeThrowsOnNullInputcovering all three null combinations:(null, "abc"),("abc", null),(null, null).Testing
All existing parameterized cases still pass. Three new null-input cases now also pass.
Checklist