You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Bruno P. Kinoshita (JIRA)" <ji...@apache.org> on 2016/11/03 22:11:00 UTC

[jira] [Comment Edited] (LANG-1281) Javadoc of StringUtils.ordinalIndexOf is contradictory.

    [ https://issues.apache.org/jira/browse/LANG-1281?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15634459#comment-15634459 ] 

Bruno P. Kinoshita edited comment on LANG-1281 at 11/3/16 10:10 PM:
--------------------------------------------------------------------

I had voted +1 for the pull request, but then read the Javadoc again, and now I'm not sure about it :-)

>"The code increments the starting index by one, rather than by the length of the match string, so matches may overlap."

I'm not sure if there's anything wrong with the above statement for StringUtils#ordinalOf.

> But the implementation of the method does NOT increment by 1 if given the empty string. So this change causes the documentation to contradict the implementation.

Given the empty string, as far as I can tell, the implementation returns (as in the doc) "the n-th index of the search CharSequence", which is 0. It never increments the starting index (which is done here https://github.com/apache/commons-lang/blob/ff4497aff8cc9de4e0b2c6e5e23e5b6550f76f29/src/main/java/org/apache/commons/lang3/StringUtils.java#L1477).

As it was given an empty string, this check in ordinalOf method returns the empty string: https://github.com/apache/commons-lang/blob/ff4497aff8cc9de4e0b2c6e5e23e5b6550f76f29/src/main/java/org/apache/commons/lang3/StringUtils.java#L1466


was (Author: kinow):
I had voted +1 for the pull request, but then read the Javadoc again, and now I'm not sure about it :-)

>"The code increments the starting index by one, rather than by the length of the match string, so matches may overlap."

I'm not sure if there's anything wrong with the above statement for StringUtils#ordinalOf.

> But the implementation of the method does NOT increment by 1 if given the empty string. So this change causes the documentation to contradict the implementation.

Given the empty string, as far as I can tell, the implementation returns (as in the doc) "the n-th index of the search CharSequence", which is 0. It never increments the starting index (which is done here https://github.com/apache/commons-lang/blob/ff4497aff8cc9de4e0b2c6e5e23e5b6550f76f29/src/main/java/org/apache/commons/lang3/StringUtils.java#L1477).

> Javadoc of StringUtils.ordinalIndexOf is contradictory.
> -------------------------------------------------------
>
>                 Key: LANG-1281
>                 URL: https://issues.apache.org/jira/browse/LANG-1281
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.5
>            Reporter: Andreas Lundblad
>            Priority: Minor
>
> Javadoc of StringUtils.ordinalIndexOf states the following:
> "The code increments the starting index by one, rather than by the length of the match string, so matches may overlap."
> But then gives the following example:
> StringUtils.ordinalIndexOf("aabaabaa", "", 2) = 0
> which clearly indicates that it does *not* increment the starting index by one in case of the empty string.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)