JDK-8055949 : ByteArrayOutputStream capacity should be maximal array size permitted by VM
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-08-25
  • Updated: 2018-07-24
  • Resolved: 2014-08-27
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 6 JDK 7 JDK 8 JDK 9
6u95Fixed 7u76Fixed 8u31Fixed 9 b29Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
It should be possible to write (almost) Integer.MAX_VALUE bytes to a ByteArrayOutputStream.  In fact, because of resizing algorithm, the effective capacity is only half that.

ByteArrayOutputStream should use the same resizing computation for huge capacities as is already done in collection classes like ArrayList.

Fix is easy.

http://cr.openjdk.java.net/~martin/webrevs/openjdk9/ByteArrayOutputStream-MAX_ARRAY_SIZE/
Comments
Amazing how my most popular changes are the ones that add just one bit of incremental scalability.
09-10-2014

Fix has been verified already in 8u40. SQE OK to take it in PSU15_01.
09-10-2014

Verified by the regression test provided with the fix, on a big memory Linux machine, with b29.
05-09-2014

I should have fixed this as part of the changeset below - I have no recollection of why it was omitted. changeset: 2350:ec45423a4700 user: martin date: 2010-05-09 00:59 -0700 6933217: Huge arrays handled poorly in core libraries Summary: Write overflow-conscious array resizing code Reviewed-by: chegar
25-08-2014