ns3154 opened a new issue, #16349:
URL: https://github.com/apache/dubbo/issues/16349
### Apache Dubbo Component
Java SDK (apache/dubbo)
### Dubbo Version
`3.3` branch (current HEAD). The method was introduced in #14924.
### Steps to reproduce this issue
`StringUtils.substringAfter("abc", ':')` returns `"abc"`.
The method's Javadoc states *"If nothing is found, the empty string is
returned."*, but when the
separator is absent it returns the original string instead:
```
substringAfter("a:b", ':') -> "b" // ok
substringAfter("abc", ':') -> "abc" // expected ""
```
### What you expected to happen
`StringUtils.substringAfter("abc", ':')` should return `""` (the empty
string), as documented.
### Root cause
In `substringAfter`, the not-found branch returns `str`:
```java
int index = str.indexOf(separator);
return index == INDEX_NOT_FOUND ? str : str.substring(index + 1);
```
This was copy-pasted from the adjacent `substringBefore`, whose contract is
to return the original
string. The sibling method `substringAfterLast` correctly returns
`EMPTY_STRING` in the same
situation, so the two "after" methods are inconsistent. The behavior also
diverges from Apache
commons-lang3's `substringAfter`, which returns the empty string when the
separator is absent.
### Impact
`substringAfter` is a public utility method. Although it currently has no
internal callers, any
future caller relying on the documented contract would silently receive the
original string instead
of an empty string.
### Are you willing to submit a pull request to fix on your own?
- [x] Yes I am willing to submit a pull request on my own!
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]