adoroszlai commented on code in PR #7182:
URL: https://github.com/apache/ozone/pull/7182#discussion_r1753746181
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/OMPBHelper.java:
##########
@@ -242,11 +242,20 @@ public static MD5MD5Crc32FileChecksumProto convert(
DataOutputBuffer buf = new DataOutputBuffer();
checksum.write(buf);
byte[] bytes = buf.getData();
- DataInputBuffer buffer = new DataInputBuffer();
- buffer.reset(bytes, 0, bytes.length);
- int bytesPerCRC = buffer.readInt();
- long crcPerBlock = buffer.readLong();
- buffer.close();
+ DataInputBuffer buffer = null;
+ int bytesPerCRC;
+ long crcPerBlock;
+ try {
+ buffer = new DataInputBuffer();
+ buffer.reset(bytes, 0, bytes.length);
+ bytesPerCRC = buffer.readInt();
+ crcPerBlock = buffer.readLong();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
Review Comment:
Since the method `throws IOException`, I don't think it's necessary to
convert it to `RuntimeException`. (In cases where conversion is needed, prefer
the more specific `UncheckedIOException`.)
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/OMPBHelper.java:
##########
@@ -242,11 +242,20 @@ public static MD5MD5Crc32FileChecksumProto convert(
DataOutputBuffer buf = new DataOutputBuffer();
checksum.write(buf);
byte[] bytes = buf.getData();
- DataInputBuffer buffer = new DataInputBuffer();
- buffer.reset(bytes, 0, bytes.length);
- int bytesPerCRC = buffer.readInt();
- long crcPerBlock = buffer.readLong();
- buffer.close();
+ DataInputBuffer buffer = null;
+ int bytesPerCRC;
+ long crcPerBlock;
+ try {
+ buffer = new DataInputBuffer();
+ buffer.reset(bytes, 0, bytes.length);
+ bytesPerCRC = buffer.readInt();
+ crcPerBlock = buffer.readLong();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally {
+ assert buffer != null;
+ buffer.close();
+ }
Review Comment:
Let's rely on auto-close:
```suggestion
int bytesPerCRC;
long crcPerBlock;
try (DataInputBuffer buffer = new DataInputBuffer()) {
buffer.reset(bytes, 0, bytes.length);
bytesPerCRC = buffer.readInt();
crcPerBlock = buffer.readLong();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]