Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4910256
Votes 0
Synopsis StringBuffer.setLength(0) - Regression-cte 4724129/Reuse.java fails in Tiger
Category java:cte_test
Reported Against tiger , tiger-beta
Release Fixed
State 11-Closed, Will Not Fix, bug
Priority: 2-High
Related Bugs 4724129
Submit Date 21-AUG-2003
Description




Filed By       : J2SE-SQA [j2se-tck-  xxxxx@xxxxx  ]
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]:
         CTE_REGTEST/Generic/4724129/Reuse.java

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)
             expandCapacity(newLength);

         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:
=====================
/net/jdk/export/jpse04/Regression/1.5.0/test/CTE_REGTEST/Generic/4724129/Reuse.java

jtr file location:
==================
/net/jtgb4u4c.sfbay/export/sail15/results.2/tiger/b15/regtest/x86/sol9_x86_cde_smp_linux-6/workDir/cte/CTE_REGTEST/Generic/4724129/Reuse.jtr

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

--- script start ---
#!/bin/sh

RESULT_DIR=`pwd`
WORK_DIR=$RESULT_DIR/workDir/test
REPORT_DIR=$RESULT_DIR/reportDir
JT_HOME="/net/linux-15/export/home/java/jct"
JAVA_HOME="/net/linux-15/export/home/java/jdk1.5.0/x86"
TEST_BASE_PATH="/net/linux-15/export/home/java/regtest.tiger/cte"

TESTWITH=$JAVA_HOME
TESTJAVA=$JAVA_HOME

JTOPTS="-server"
TESTVMOPTS="-server"

CLASSPATH="$JT_HOME/classes:$JT_HOME/lib/javatest.jar:$JT_HOME/lib/jtreg.jar:$JT_HOME/jemmy/jemmy.jar"

export JAVA_HOME
export JT_HOME
export TESTWITH
export CLASSPATH

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):
=======================
----------System.out:(0/0)----------
----------System.err:(13/711)----------
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)



======================================================================
Work Around
N/A
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.
  xxxxx@xxxxx   2003-08-26

Testcase 4724129 is no longer applicable to tiger. So removing the testcase from testsuite.

  xxxxx@xxxxx   2004-01-15
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang