diff --git a/src/java/org/apache/commons/lang/text/StrBuilder.java b/src/java/org/apache/commons/lang/text/StrBuilder.java index 13281cefe..fd135fd11 100644 --- a/src/java/org/apache/commons/lang/text/StrBuilder.java +++ b/src/java/org/apache/commons/lang/text/StrBuilder.java @@ -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); diff --git a/src/test/org/apache/commons/lang/text/StrBuilderTest.java b/src/test/org/apache/commons/lang/text/StrBuilderTest.java index 67e1ce1df..d58930805 100644 --- a/src/test/org/apache/commons/lang/text/StrBuilderTest.java +++ b/src/test/org/apache/commons/lang/text/StrBuilderTest.java @@ -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()); + } + }