Fix setLength()
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@230906 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8048e49d99
commit
e6f6b0dbfa
|
@ -155,7 +155,7 @@ public class StrBuilder implements Cloneable {
|
|||
}
|
||||
if (length < size) {
|
||||
size = length;
|
||||
} else {
|
||||
} else if (length > size) {
|
||||
ensureCapacity(length);
|
||||
int oldEnd = size;
|
||||
int newEnd = length;
|
||||
|
|
|
@ -269,8 +269,12 @@ public class StrBuilderTest extends TestCase {
|
|||
public void testSetLength() {
|
||||
StrBuilder sb = new StrBuilder();
|
||||
sb.append("Hello");
|
||||
sb.setLength(2);
|
||||
sb.setLength(2); // shorten
|
||||
assertEquals("He", sb.toString());
|
||||
sb.setLength(2); // no change
|
||||
assertEquals("He", sb.toString());
|
||||
sb.setLength(3); // lengthen
|
||||
assertEquals("He\0", sb.toString());
|
||||
|
||||
try {
|
||||
sb.setLength(-1);
|
||||
|
|
Loading…
Reference in New Issue