From 7ea69942ef82e8ad565a4c68d5ac926a4385d7ef Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 27 Aug 2005 13:40:14 +0000 Subject: [PATCH] Fix IndexOutOfBoundsException on padding bug 35756, from Reuben Sivan git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@240418 13f79535-47bb-0310-9956-ffa450edef68 --- project.xml | 3 +++ src/java/org/apache/commons/lang/StringUtils.java | 3 ++- src/test/org/apache/commons/lang/StringUtilsTest.java | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/project.xml b/project.xml index c748ebc11..eb0f803fd 100644 --- a/project.xml +++ b/project.xml @@ -301,6 +301,9 @@ limitations under the License. Sean Schofield + + Reuben Sivan + Ville Skytta diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java index 4ed9a1c3e..4a8f7e177 100644 --- a/src/java/org/apache/commons/lang/StringUtils.java +++ b/src/java/org/apache/commons/lang/StringUtils.java @@ -110,6 +110,7 @@ import java.util.List; * @author Phil Steitz * @author Al Chou * @author Michael Davey + * @author Reuben Sivan * @since 1.0 * @version $Id$ */ @@ -152,7 +153,7 @@ public class StringUtils { * *

Used for efficient space padding. The length of each String expands as needed.

*/ - private static final String[] PADDING = new String[Character.MAX_VALUE]; + private static final String[] PADDING = new String[Character.MAX_VALUE + 1]; static { // space padding is most common, start with 64 chars diff --git a/src/test/org/apache/commons/lang/StringUtilsTest.java b/src/test/org/apache/commons/lang/StringUtilsTest.java index 798363642..9d067d52d 100644 --- a/src/test/org/apache/commons/lang/StringUtilsTest.java +++ b/src/test/org/apache/commons/lang/StringUtilsTest.java @@ -1126,6 +1126,7 @@ public class StringUtilsTest extends TestCase { assertEquals(" ", StringUtils.leftPad("", 5, ' ')); assertEquals(" abc", StringUtils.leftPad("abc", 5, ' ')); assertEquals("xxabc", StringUtils.leftPad("abc", 5, 'x')); + assertEquals("\uffff\uffffabc", StringUtils.leftPad("abc", 5, '\uffff')); assertEquals("abc", StringUtils.leftPad("abc", 2, ' ')); String str = StringUtils.leftPad("aaa", 10000, 'a'); // bigger than pad length assertEquals(10000, str.length());