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:
Henri Yandell 2006-10-31 23:00:54 +00:00
parent 8e52e2169b
commit 1a158281aa
2 changed files with 10 additions and 2 deletions

View File

@ -1670,7 +1670,7 @@ public String midString(int index, int length) {
*/
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 int indexOf(char ch, int startIndex) {
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;
}

View File

@ -1741,4 +1741,12 @@ public void testIndexOfLang294() {
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'));
}
}