Repository: activemq Updated Branches: refs/heads/master 0dd806f43 -> 351faf269
https://issues.apache.org/jira/browse/AMQ-6445 Fixing RandomAccessFile usage so that the file will be properly closed even if there is an exception Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/351faf26 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/351faf26 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/351faf26 Branch: refs/heads/master Commit: 351faf26992f1406bf203b0cefd1238615baf88c Parents: 0dd806f Author: Christopher L. Shannon (cshannon) <[email protected]> Authored: Thu Sep 29 06:16:40 2016 -0400 Committer: Christopher L. Shannon (cshannon) <[email protected]> Committed: Thu Sep 29 06:16:40 2016 -0400 ---------------------------------------------------------------------- .../activemq/store/kahadb/disk/journal/Journal.java | 4 +--- .../activemq/store/kahadb/disk/util/DiskBenchmark.java | 10 +++++----- 2 files changed, 6 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/351faf26/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java ---------------------------------------------------------------------- diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java index e526698..a417adf 100644 --- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java +++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java @@ -374,10 +374,8 @@ public class Journal { } private void doPreallocationKernelCopy(RecoverableRandomAccessFile file) { - try { - RandomAccessFile templateRaf = new RandomAccessFile(osKernelCopyTemplateFile, "rw"); + try (RandomAccessFile templateRaf = new RandomAccessFile(osKernelCopyTemplateFile, "rw");){ templateRaf.getChannel().transferTo(0, getMaxFileLength(), file.getChannel()); - templateRaf.close(); } catch (ClosedByInterruptException ignored) { LOG.trace("Could not preallocate journal file with kernel copy", ignored); } catch (FileNotFoundException e) { http://git-wip-us.apache.org/repos/asf/activemq/blob/351faf26/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/util/DiskBenchmark.java ---------------------------------------------------------------------- diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/util/DiskBenchmark.java b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/util/DiskBenchmark.java index f59e1c3..b6388b8 100644 --- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/util/DiskBenchmark.java +++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/util/DiskBenchmark.java @@ -300,11 +300,11 @@ public class DiskBenchmark { if (tmpFile.exists()) { tmpFile.delete(); } - RandomAccessFile templateFile = new RandomAccessFile(tmpFile, "rw"); - templateFile.setLength(size); - templateFile.getChannel().force(true); - templateFile.getChannel().transferTo(0, size, raf.getChannel()); - templateFile.close(); + try (RandomAccessFile templateFile = new RandomAccessFile(tmpFile, "rw");) { + templateFile.setLength(size); + templateFile.getChannel().force(true); + templateFile.getChannel().transferTo(0, size, raf.getChannel()); + } tmpFile.delete(); }
