RFR: 8055949: ByteArrayOutputStream capacity should be maximal array size permitted by VM

Ulf Zibis Ulf.Zibis at CoSoCo.de
Wed Aug 27 10:41:47 UTC 2014

Am 25.08.2014 um 19:37 schrieb Martin Buchholz:
> https://bugs.openjdk.java.net/browse/JDK-8055949
> http://cr.openjdk.java.net/~martin/webrevs/openjdk9/ByteArrayOutputStream-MAX_ARRAY_SIZE/
> The 2x capacity gap was noticed by real users!

Hi Martin,

the MAX_ARRAY_SIZE code now is copied to many places in JDK. Couldn't you better centralize the code 
to one place, e.g. j.u.Arrays or some hidden class of sun.java...?
Isn't there a property to retrieve MAX_ARRAY_SIZE from the running VM?

Imagine, some VM throws OOME above Integer.MAX_VALUE-4 and minCapacity is Integer.MAX_VALUE-4.
With this code a OOME will happen:
  124         return (minCapacity > MAX_ARRAY_SIZE) ?
  125             Integer.MAX_VALUE :
  126             MAX_ARRAY_SIZE;
With this code we would avoid the OOME:
  124         return (minCapacity > MAX_ARRAY_SIZE) ?
  125             minCapacity :
  126             MAX_ARRAY_SIZE;


More information about the core-libs-dev mailing list