Steps to reproduce:
1. Call the method like that:
Actual result: the value of count variable equals 3
Expected result: the value of count variable equals 4
The substrings are highlighted in red:
Method returns incorrect value because of this code:
This looks like a greedy algorithm - but increasing the idx variable by the length of substring could lead to the problems like in example:
Let's say that idx = 6, so we try to find a substring in the highlighted suffix:
We found the substring, so idx now becomes idx + 3 = 9. So now this suffix will be used for searching substring in it:
But because of increasing the value of idx by 3 we won't find the substring (abaabaababaab) which intersects with the already found substring on the last step.
Basically, this method will work incorrectly with any substrings that intersect with each other.
There is also a unit test with incorrect expected value:
If this behavior (counting substrings that do not intersect) is intended, please update the JavaDoc to reflect it. Right now it looks like that:
Link for the PR: https://github.com/apache/commons-lang/pull/615