diff --git a/src/main/java/net/openhft/chronicle/hash/impl/util/CanonicalRandomAccessFiles.java b/src/main/java/net/openhft/chronicle/hash/impl/util/CanonicalRandomAccessFiles.java index 311815e04..02d2ce273 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/util/CanonicalRandomAccessFiles.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/util/CanonicalRandomAccessFiles.java @@ -16,6 +16,7 @@ package net.openhft.chronicle.hash.impl.util; +import net.openhft.chronicle.core.CleaningRandomAccessFile; import net.openhft.chronicle.core.Jvm; import java.io.File; @@ -36,7 +37,7 @@ public final class CanonicalRandomAccessFiles { return canonicalRafs.compute(file, (f, ref) -> { if (ref == null) { try { - return new RafReference(new RandomAccessFile(f, "rw")); + return new RafReference(new CleaningRandomAccessFile(f, "rw")); } catch (FileNotFoundException e) { throw Jvm.rethrow(e); } diff --git a/src/test/java/net/openhft/chronicle/set/Builder.java b/src/test/java/net/openhft/chronicle/set/Builder.java index bed10ca9e..2edde079c 100644 --- a/src/test/java/net/openhft/chronicle/set/Builder.java +++ b/src/test/java/net/openhft/chronicle/set/Builder.java @@ -44,8 +44,9 @@ public class Builder { This will only work if the user is an admin on windows. */ file.setWritable(true);//just in case relative path was used. - RandomAccessFile raf = new RandomAccessFile(file, "rw"); - raf.close();//allows closing the file access on windows. forcing to close access. Only works for admin-access. + try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) { + //allows closing the file access on windows. forcing to close access. Only works for admin-access. + } } //file.delete(); //isnt guaranteed on windows.