RFR: 8374610: Make ByteArrayOutputStream.ensureCapacity(int) protected
Roger Riggs
rriggs at openjdk.org
Fri Jan 16 13:59:42 UTC 2026
On Mon, 12 Jan 2026 22:13:06 GMT, Daniel Gredler <dgredler at openjdk.org> wrote:
> ByteArrayOutputStream.ensureCapacity(int) is currently private. It would be useful if it were protected, so that it can be more easily extended by subclasses.
>
> Mailing list discussion: https://mail.openjdk.org/pipermail/core-libs-dev/2026-January/156983.html
Existing subclasses of BAOS, that are adding new methods, either have to check the capacity directly with the buffer themselves or call superclass implementations to write to the buffer, and those ensure the capacity. So I don't think there is a risk to existing subclasses.
Calling `ensureCapacity` is an optimization to pre-size the buffer. A new subclass still has to deal with checking against the buffer array size or use existing methods to do the writes. So no new risk in that.
If there is any new advice to be given, it is just being explicit about the current advice, check the buffer sizes yourself or call existing write methods.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/29180#issuecomment-3760130999
More information about the core-libs-dev
mailing list