Repository navigation
[SHRINKWRAP-546] Using try-with-resources where appropriate - #178
Conversation
8a4d67d to
ec4e448
Compare
ec4e448 to
35f3376
Compare
| } | ||
| }; | ||
| Assertions.assertThrows(ArchiveExportException.class, () -> IOUtil.copyWithClose(in, sink)); | ||
| try (// Export |
There was a problem hiding this comment.
I believe this would look better as:
try (final InputStream in = this.exportAsInputStream(archive); // Export
| */ | ||
| private static SerializableView serializeAndDeserialize(final SerializableView archive) throws IOException, ClassNotFoundException { | ||
| assert archive != null : "Archive must be specified"; | ||
| //there are failing tests for JDK 8 with error message "ID not as expected after serialization" if we put this stream in try-with-resources |
There was a problem hiding this comment.
final ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
try (final ObjectOutputStream out = new ObjectOutputStream(byteOut)) {
out.writeObject(archive);
}
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteOut.toByteArray()))) {
return (SerializableView) in.readObject();
}
There was a problem hiding this comment.
I am not sure what exactly changed since the last time I was testing this but now everything looks okay when I put both of the streams in try-with-resources statement and run it locally, so I will use the statement and remove the comments.
There was a problem hiding this comment.
Just a note here, but having the ByteArrayOutputStream inside the try clause is redundant. Documentation states that "Closing a ByteArrayOutputStream has no effect." and if you have a look inside the ByteArrayOutputStream you can see that the close method is empty.
But no harm in leaving it as is, just a fun fact
|
Just two small things to have a look at @khermano , otherwise this looks good |
35f3376 to
175ed29
Compare
Issue: https://issues.redhat.com/browse/SHRINKWRAP-546