Applying my patch from LANG-412; fixing Peter Oxenham's report that the appendFixedWidthPadRight and appendFixedWidthPadLeft are not null safe if the nullText has not been set

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@627248 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2008-02-13 05:44:46 +00:00
parent 2e8e3f46ba
commit 1fe5439baf
2 changed files with 19 additions and 0 deletions

View File

@ -1183,6 +1183,9 @@ public class StrBuilder implements Cloneable {
if (width > 0) {
ensureCapacity(size + width);
String str = (obj == null ? getNullText() : obj.toString());
if (str == null) {
str = "";
}
int strLen = str.length();
if (strLen >= width) {
str.getChars(strLen - width, strLen, buffer, size);
@ -1227,6 +1230,9 @@ public class StrBuilder implements Cloneable {
if (width > 0) {
ensureCapacity(size + width);
String str = (obj == null ? getNullText() : obj.toString());
if (str == null) {
str = "";
}
int strLen = str.length();
if (strLen >= width) {
str.getChars(0, width, buffer, size);

View File

@ -1749,4 +1749,17 @@ public class StrBuilderTest extends TestCase {
assertEquals( "The indexOf(char) method is looking beyond the end of the string", -1, sb.indexOf('h'));
}
//-----------------------------------------------------------------------
public void testLang412Right() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadRight(null, 10, '*');
assertEquals( "Failed to invoke appendFixedWidthPadRight correctly", "**********", sb.toString());
}
public void testLang412Left() {
StrBuilder sb = new StrBuilder();
sb.appendFixedWidthPadLeft(null, 10, '*');
assertEquals( "Failed to invoke appendFixedWidthPadLeft correctly", "**********", sb.toString());
}
}