You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Henri Yandell (JIRA)" <ji...@apache.org> on 2006/12/12 23:37:22 UTC
[jira] Resolved: (LANG-299) Bug in method appendFixedWidthPadRight
of class StrBuilder causes an ArrayIndexOutOfBoundsException
[ http://issues.apache.org/jira/browse/LANG-299?page=all ]
Henri Yandell resolved LANG-299.
--------------------------------
Fix Version/s: 2.3
Resolution: Fixed
Applying my patch. Took a bit to find out the actual failing test as you either have to make the StrBuilder smaller than 32 by default, or have big strings.
svn ci -m "Applying a unit test for LANG-299 and the fix that Francisco Benavent suggests. "
Sending src/java/org/apache/commons/lang/text/StrBuilder.java
Sending src/test/org/apache/commons/lang/text/StrBuilderAppendInsertTest.java
Transmitting file data ..
Committed revision 486377.
> Bug in method appendFixedWidthPadRight of class StrBuilder causes an ArrayIndexOutOfBoundsException
> ---------------------------------------------------------------------------------------------------
>
> Key: LANG-299
> URL: http://issues.apache.org/jira/browse/LANG-299
> Project: Commons Lang
> Issue Type: Bug
> Affects Versions: 2.2
> Reporter: Francisco Benavent
> Fix For: 2.3
>
> Attachments: LANG-299.patch
>
>
> There's a bug in method appendFixedWidthPadRight of class StrBuilder:
> public StrBuilder appendFixedWidthPadRight(Object obj, int width, char padChar) {
> if (width > 0) {
> ensureCapacity(size + width);
> String str = (obj == null ? getNullText() : obj.toString());
> int strLen = str.length();
> if (strLen >= width) {
> ==> str.getChars(0, strLen, buffer, size); <==== BUG: it should be str.getChars(0, width, buffer, size);
> } else {
> int padLen = width - strLen;
> str.getChars(0, strLen, buffer, size);
> for (int i = 0; i < padLen; i++) {
> buffer[size + strLen + i] = padChar;
> }
> }
> size += width;
> }
> return this;
> }
> This is causing an ArrayIndexOutOfBoundsException, so this method is unusable when strLen > width.
> It's counterpart method appendFixedWidthPadLeft seems to be ok.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org