You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "ns3154 (via GitHub)" <gi...@apache.org> on 2026/06/19 05:32:26 UTC

[I] [Bug] StringUtils.substringAfter returns the original string instead of an empty string when the separator is absent [dubbo]

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: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [Bug] StringUtils.substringAfter returns the original string instead of an empty string when the separator is absent [dubbo]

Posted by "zrlw (via GitHub)" <gi...@apache.org>.
zrlw commented on issue #16349:
URL: https://github.com/apache/dubbo/issues/16349#issuecomment-4777702135

   the method is not used, maybe we should delete it directly.


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [Bug] StringUtils.substringAfter returns the original string instead of an empty string when the separator is absent [dubbo]

Posted by "zrlw (via GitHub)" <gi...@apache.org>.
zrlw closed issue #16349: [Bug] StringUtils.substringAfter returns the original string instead of an empty string when the separator is absent
URL: https://github.com/apache/dubbo/issues/16349


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org