JDK-4910256 : StringBuffer.setLength(0) - Regression-cte 4724129/Reuse.java fails in Tiger
  • Type: Bug
  • Component: other-libs
  • Sub-Component: other
  • Affected Version: 5.0
  • Priority: P2
  • Status: Closed
  • Resolution: Won't Fix
  • OS:
    linux,solaris_9,solaris_10,windows_xp linux,solaris_9,solaris_10,windows_xp
  • CPU: x86
  • Submitted: 2003-08-21
  • Updated: 2005-11-14
  • Resolved: 2004-01-15
Related Reports
Relates :  

Name: vsR10238			Date: 08/21/2003

Filed By       : J2SE-SQA [###@###.###
JDK            : JDK1.5.0-b15
Testbase       : Regression-cte
Platform[s]    : Windows XP Home, Solaris 10 (sparc) (GNOME), Solaris 9 (x86) (CDE)
switch/Mode    : -client, -server
Falling test[s]:

Regression-cte CTE_REGTEST/Generic/4724129/Reuse.java test fails with JDK1.5.0.
The test explicitly checks for capacity() to be 16 after setLength(0).
But java.lang.AbstractStringBuilder.setLength does not reallocate value in JDK1.5.0:

     public void setLength(int newLength) {
         if (newLength < 0)
             throw new StringIndexOutOfBoundsException(newLength);
         if (newLength > value.length)

         if (count < newLength) {
             for (; count < newLength; count++)
                 value[count] = '\0';
         } else {
             count = newLength;

The test passes with JDK1.4.2, because java.lang.StringBuffer.setLength(0) reallocates value:
     value = new char[16];

4724129 mentions this issue.

But since 4724129 does not list Tiger in its releases,
because it mentions StringBuffer.toString as the primary cause of the problem,
and because this failure can be considered as a test bug according to
Michael McCloskey's comments, I am opening a new bug for this issue for Tiger.

Below are Michael McCloskey's comments:

"In Kestrel a special case was put into StringBuffer to detect if someone
was reusing a buffer (setlength(0)) and in that case the backing array
was resized to 16. That was an optimization for some usage patterns but
it was unacceptable to others, as well as violating the spec since it
changed the backing capacity in a way that was not documented."

Please fill free to reassign the bug to java/cte_test if java.lang.AbstractStringBuilder.setLength
behaves correctly in Tiger and the test should be changed or excluded.

Test source location:

jtr file location:

How to reproduce:
Run the following script (you may need to change its variables)

--- script start ---





export JAVA_HOME
export JT_HOME

mkdir -p $WORK_DIR/scratch 2>&1
mkdir -p $WORK_DIR/jtData 2>&1
mkdir -p $REPORT_DIR 2>&1

#rm $WORK_DIR/jtData/ResultCache.jtw 2>&1

cd $WORK_DIR/scratch

$JAVA_HOME/bin/java -cp $CLASSPATH $JTOPTS -DenvVars=TESTJAVAHOME=$JAVA_HOME,TESTVMOPTS=$TESTVMOPTS,DISPLAY=:0,HOME=$HOME/.regtest,PATH=/bin:/usr/bin,CPAPPEND=$JT_HOME/jemmy/jemmy.jar,TZ=,LC_ALL=en_US,LC_CTYPE=en_US,LANG=en_US,LPDEST= -DDISPLAY=:0 -DlocalHost="linux-6" -Dprogram=jtreg com.sun.javatest.regtest.Main -a -v default -batch -params -w "$WORK_DIR" -r "$REPORT_DIR" -t "$TEST_BASE_PATH" "$TEST_BASE_PATH/CTE_REGTEST/Generic/4724129/Reuse.java"

--- script end ---

Script output:

Test output (jtr part):
java.lang.RuntimeException: Bug#4724129:Test failed
	at Reuse.main(Reuse.java:18)
	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:324)
	at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:82)
	at java.lang.Thread.run(Thread.java:549)

JavaTest Message: Test threw exception: java.lang.RuntimeException: Bug#4724129:Test failed
JavaTest Message: shutting down test

STATUS:Failed.`main' threw exception: java.lang.RuntimeException: Bug#4724129:Test failed
result: Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Bug#4724129:Test failed

test result: Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Bug#4724129:Test failed

Specific machine info:
Hostname: linux-21
OS: Windows XP Home
Hostname: linux-6
OS: Solaris 9 (x86) (CDE)
Hostname: linux-8
OS: Solaris 10 (sparc) (GNOME)


EVALUATION StringBuilder/Buffer.setLength should not change the allocation size in Tiger. The String created from the builder/buffer no longer uses the same backing array and so that hack is no longer required. ###@###.### 2003-08-26 Testcase 4724129 is no longer applicable to tiger. So removing the testcase from testsuite. ###@###.### 2004-01-15