Skip to content

fix: add null input validation to AlternativeStringArrange.arrange()#7425

Merged
DenizAltunkapan merged 2 commits into
TheAlgorithms:masterfrom
Shubh2-0:fix-alternative-string-arrange-null-handling
May 18, 2026
Merged

fix: add null input validation to AlternativeStringArrange.arrange()#7425
DenizAltunkapan merged 2 commits into
TheAlgorithms:masterfrom
Shubh2-0:fix-alternative-string-arrange-null-handling

Conversation

@Shubh2-0
Copy link
Copy Markdown
Contributor

What

Adds explicit null-input validation to AlternativeStringArrange.arrange().

Previously, calling arrange(null, "abc") (or with the second argument null, or both null) threw a NullPointerException from inside the method with no useful message. After this change, it throws an IllegalArgumentException with the message "Input strings must not be null", matching the fail-fast convention already used by other utility classes in this package (for example HammingDistance.calculateHammingDistance).

Why

  • Clearer contract: @throws IllegalArgumentException is now documented in the Javadoc, so callers know what to expect.
  • Better error message: an NPE with no message is hard to debug. "Input strings must not be null" makes the cause obvious.
  • Consistency: aligns with the pattern in HammingDistance and other string utilities in this package.
  • No behavior change for valid inputs: all existing test cases continue to pass unchanged.

Changes

  1. src/main/java/.../AlternativeStringArrange.java

    • Added a null guard at the top of arrange() throwing IllegalArgumentException.
    • Updated the method Javadoc with @throws and a note that inputs must be non-null.
  2. src/test/java/.../AlternativeStringArrangeTest.java

    • Added a parameterized test arrangeThrowsOnNullInput covering all three null combinations: (null, "abc"), ("abc", null), (null, null).
    • Verifies both the exception type and the message.

Testing

All existing parameterized cases still pass. Three new null-input cases now also pass.

Checklist

  • My code follows the code style of this project.
  • My code does not cause any duplication.
  • All new and existing tests pass.
  • All new code is covered by unit tests.
  • No new warnings are generated.

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-commenter
Copy link
Copy Markdown

codecov-commenter commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.63%. Comparing base (8848ed1) to head (e8bc28f).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DenizAltunkapan DenizAltunkapan merged commit 4b8099c into TheAlgorithms:master May 18, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants