Fixng LANG-295 - thisBuf.length calls. There were two of the calls, so I've committed a unit test showing things are broken and a fix in both cases.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@469696 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8e52e2169b
commit
1a158281aa
|
@ -1670,7 +1670,7 @@ public class StrBuilder implements Cloneable {
|
|||
*/
|
||||
public boolean contains(char ch) {
|
||||
char[] thisBuf = buffer;
|
||||
for (int i = 0; i < thisBuf.length; i++) {
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
if (thisBuf[i] == ch) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1727,7 +1727,7 @@ public class StrBuilder implements Cloneable {
|
|||
return -1;
|
||||
}
|
||||
char[] thisBuf = buffer;
|
||||
for (int i = startIndex; i < thisBuf.length; i++) {
|
||||
for (int i = startIndex; i < size; i++) {
|
||||
if (thisBuf[i] == ch) {
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -1741,4 +1741,12 @@ public class StrBuilderTest extends TestCase {
|
|||
assertEquals(-1, sb.indexOf("three"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testLang295() {
|
||||
StrBuilder sb = new StrBuilder("onetwothree");
|
||||
sb.deleteFirst("three");
|
||||
assertFalse( "The contains(char) method is looking beyond the end of the string", sb.contains('h'));
|
||||
assertEquals( "The indexOf(char) method is looking beyond the end of the string", -1, sb.indexOf('h'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue