JDK-6952330 : Fix for 6933217 broke contract of StringBuffer.ensureCapacity
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2010-05-13
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b97Fixed
Related Reports
Relates :  
Description
The fix for 6933217 inadvertently changed the array expansion algorithm for StringBuffer (et al) ensureCapacity to simply double the size; however the specification requires that it expand by 2N+2.

Comments
PUBLIC COMMENTS If it helps, I found an open test that should demonstrate it: http://www.sourceware.org/cgi-bin/cvsweb.cgi/mauve/gnu/testlet/java/lang/StringBuffer/StringBufferTest.java?rev=1.7&content-type=text/x-cvsweb-markup&cvsroot=mauve -kto
13-05-2010

SUGGESTED FIX http://cr.openjdk.java.net/~martin/webrevs/openjdk7/StringBuffer-capacity/StringBuffer-capacity.patch diff --git a/src/share/classes/java/lang/AbstractStringBuilder.java b/src/share/classes/java/lang/AbstractStringBuilder.java --- a/src/share/classes/java/lang/AbstractStringBuilder.java +++ b/src/share/classes/java/lang/AbstractStringBuilder.java @@ -117,7 +117,7 @@ * size check or synchronization. */ void expandCapacity(int minimumCapacity) { - int newCapacity = value.length * 2; + int newCapacity = value.length * 2 + 2;
13-05-2010

EVALUATION See description.
13-05-2010