commons-lang icon indicating copy to clipboard operation
commons-lang copied to clipboard

Close/flush the `OutputStream` before calling `toByteArray()` on underlying `ByteArrayOutputStream`

Open emopers opened this issue 5 years ago • 2 comments

When an OutputStream instance wraps an underlying ByteArrayOutputStream instance, it is recommended to flush or close the OutputStream before invoking the underlying instances' toByteArray(). Although in some of these case it is not strictly necessary because the writeObject() method is invoked right before toByteArray(), and writeObject() internally calls flush()/drain(). However, it is good practice to call flush()/close() explicitly as mentioned, for example, here.

This pull request adds a call to close() or flush() before calls to toByteArray().

emopers avatar Jan 23 '19 08:01 emopers

Coverage Status

Coverage remained the same at 95.273% when pulling 3070ab66af7a238428f4ef8b3477ecb1e272cfcf on emopers:flushViolationFixes into b00e65686eb1b11c0b814c4aa0d6a22c03be958c on apache:master.

coveralls avatar Jan 23 '19 08:01 coveralls

@emopers Please rebase on master.

garydgregory avatar Oct 16 '20 14:10 garydgregory