[ 
http://issues.apache.org/jira/browse/LANG-294?page=comments#action_12446081 ] 
            
Henri Yandell commented on LANG-294:
------------------------------------

The bug is actually in indexOf. Here's a test for it:

    public void testIndexOfLang294() {
        StrBuilder sb = new StrBuilder("onetwothree");
        sb.deleteFirst("three");
        assertEquals(-1, sb.indexOf("three"));  // fails as the indexOf is 6
    }

The problem being that IndexOf does not look at whether it has gone over the 
actual size of the String being built and into the flotsam that is floating at 
the end of the buffer array beyond the length of the size variable.

> StrBuilder.replaceAll and StrBuilder.deleteAll can throw 
> ArrayIndexOutOfBoundsException.
> ----------------------------------------------------------------------------------------
>
>                 Key: LANG-294
>                 URL: http://issues.apache.org/jira/browse/LANG-294
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.2
>         Environment: Java 1.5.0_09, win XP Pro.
>            Reporter: Andy Lehane
>             Fix For: 3.0
>
>
> StrBuilder.replaceAll and StrBuilder.deleteAll can thrown 
> ArrayIndexOutOfBoundsException's. Here are a couple of additions to the 
> StrBuilderTest class that demonstrate this problem:
> StrBuilder.deleteAll() - added to testDeleteAll_String():
>         sb = new StrBuilder("\n%BLAH%\nDo more stuff\neven more 
> stuff\n%BLAH%\n");
>         sb.deleteAll("\n%BLAH%");
>         assertEquals("\nDo more stuff\neven more stuff\n", sb.toString());
> this causes the following error:
> java.lang.ArrayIndexOutOfBoundsException
>       at java.lang.System.arraycopy(Native Method)
>       at 
> org.apache.commons.lang.text.StrBuilder.deleteImpl(StrBuilder.java:1114)
>       at 
> org.apache.commons.lang.text.StrBuilder.deleteAll(StrBuilder.java:1188)
>       at 
> org.apache.commons.lang.text.StrBuilderTest.testDeleteAll_String(StrBuilderTest.java:606)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:585)
>       at junit.framework.TestCase.runTest(TestCase.java:154)
>       at junit.framework.TestCase.runBare(TestCase.java:127)
>       at junit.framework.TestResult$1.protect(TestResult.java:106)
>       at junit.framework.TestResult.runProtected(TestResult.java:124)
>       at junit.framework.TestResult.run(TestResult.java:109)
>       at junit.framework.TestCase.run(TestCase.java:118)
>       at junit.framework.TestSuite.runTest(TestSuite.java:208)
>       at junit.framework.TestSuite.run(TestSuite.java:203)
>       at 
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
>       at 
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> StrBuilder.replaceAll() - added to testReplaceAll_String_String():
>         sb = new StrBuilder("\n%BLAH%\nDo more stuff\neven more 
> stuff\n%BLAH%\n");
>         sb.replaceAll("\n%BLAH%", "");
>         assertEquals("\nDo more stuff\neven more stuff\n", sb.toString());
> this causes the exception:
> java.lang.ArrayIndexOutOfBoundsException
>       at java.lang.System.arraycopy(Native Method)
>       at 
> org.apache.commons.lang.text.StrBuilder.replaceImpl(StrBuilder.java:1256)
>       at 
> org.apache.commons.lang.text.StrBuilder.replaceAll(StrBuilder.java:1339)
>       at 
> org.apache.commons.lang.text.StrBuilderTest.testReplaceAll_String_String(StrBuilderTest.java:763)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:585)
>       at junit.framework.TestCase.runTest(TestCase.java:154)
>       at junit.framework.TestCase.runBare(TestCase.java:127)
>       at junit.framework.TestResult$1.protect(TestResult.java:106)
>       at junit.framework.TestResult.runProtected(TestResult.java:124)
>       at junit.framework.TestResult.run(TestResult.java:109)
>       at junit.framework.TestCase.run(TestCase.java:118)
>       at junit.framework.TestSuite.runTest(TestSuite.java:208)
>       at junit.framework.TestSuite.run(TestSuite.java:203)
>       at 
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
>       at 
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

-- 
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to