Skip to content

Commit

Permalink
GH-995: Close ObjectOutputStream in EHD2
Browse files Browse the repository at this point in the history
Fixes #995

Doesn't really make a difference because `writeObject()` drains
all data to the underlying output stream and `flush()` and `close()`
are no-ops for `ByteArrayOutputStream`.

But, technically, correct.

**cherry-pick to 2.2.x**
  • Loading branch information
garyrussell authored and artembilan committed Mar 13, 2019
1 parent f5b6927 commit 764509d
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -199,16 +199,17 @@ public void close() {
private void deserializationException(Headers headers, byte[] data, Exception e) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DeserializationException exception = new DeserializationException("failed to deserialize", data, this.isKey, e);
try {
new ObjectOutputStream(stream).writeObject(exception);
try (ObjectOutputStream oos = new ObjectOutputStream(stream)) {
oos.writeObject(exception);
}
catch (IOException ex) {
try {
stream = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(stream)) {
exception = new DeserializationException("failed to deserialize",
data, this.isKey, new RuntimeException("Could not deserialize type "
+ e.getClass().getName() + " with message " + e.getMessage()
+ " failure: " + ex.getMessage()));
new ObjectOutputStream(stream).writeObject(exception);
oos.writeObject(exception);
}
catch (IOException ex2) {
throw new IllegalStateException("Could not serialize a DeserializationException", ex2); // NOSONAR
Expand Down

0 comments on commit 764509d

Please sign in to comment.