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

Close ObjectOutputStream before calling toByteArray on underlying ByteArrayOutputStream

Open emopers opened this issue 6 years ago • 0 comments

When an ObjectOutputStream instance wraps an underlying ByteArrayOutputStream instance, it is recommended to flush or close the ObjectOutputStream before invoking the underlying instances's toByteArray(). Although in these cases it is not strictly necessary because 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 the close method before calls to the toByteArray methods.

emopers avatar Jul 11 '19 03:07 emopers