xxxJLxxx opened a new pull request, #1522:
URL: https://github.com/apache/commons-lang/pull/1522
### Motivation
`StringUtils#abbreviate(...)` currently validates `maxWidth` before checking
whether the input string already fits within the given width. As a result,
an `IllegalArgumentException` can be thrown even when no abbreviation would
be performed because `str.length() <= maxWidth`.
This behavior contradicts the documented contract of the `abbreviate`
methods, which state that the original string should be returned unchanged
when its length does not exceed `maxWidth`.
### Changes
- Reordered the internal checks in
`abbreviate(String, String, int, int)` to return early when the input
already fits within `maxWidth`.
- Preserved all existing validation and exception behavior for cases where
an abbreviation is actually required.
- Added contract tests covering both the non-throwing behavior for short
strings and the existing exception behavior when `maxWidth` is too small
and abbreviation is needed.
### Result
The method no longer throws an `IllegalArgumentException` in cases where no
abbreviation is required, while maintaining backward-compatible behavior
for all other scenarios.
### Tests
New JUnit tests have been added to verify the corrected behavior.
--
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]