commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r627248 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/text/StrBuilder.java test/org/apache/commons/lang/text/StrBuilderTest.java
Date Wed, 13 Feb 2008 05:44:49 GMT
Author: bayard
Date: Tue Feb 12 21:44:46 2008
New Revision: 627248

URL: http://svn.apache.org/viewvc?rev=627248&view=rev
Log:
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

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java?rev=627248&r1=627247&r2=627248&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java Tue Feb
12 21:44:46 2008
@@ -1183,6 +1183,9 @@
         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 @@
         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);

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java?rev=627248&r1=627247&r2=627248&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java Tue
Feb 12 21:44:46 2008
@@ -1749,4 +1749,17 @@
         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());
+    }
+
 }



Mime
View raw message