diff --git a/metrix-mapping/src/main/java/com/powsybl/metrix/mapping/timeseries/MmapByteBufferService.java b/metrix-mapping/src/main/java/com/powsybl/metrix/mapping/timeseries/MmapByteBufferService.java index 4e30fa34..22422e68 100644 --- a/metrix-mapping/src/main/java/com/powsybl/metrix/mapping/timeseries/MmapByteBufferService.java +++ b/metrix-mapping/src/main/java/com/powsybl/metrix/mapping/timeseries/MmapByteBufferService.java @@ -35,10 +35,9 @@ /** * Memory mapped file buffer allocation service. * Main purpose of this utility class is to overcome a Java issue on Windows with memory mapped file. - * Once Random access file is closed, file cannot be delete until buffer has been garbage collected. + * Once Random access file is closed, file cannot be deleted until buffer has been garbage collected. * The workaround used here is to start a "cleaner" thread that try to delete the file every minute. - */ -/** + * * @author Paul Bui-Quang {@literal } */ @@ -119,11 +118,13 @@ public ByteBuffer create(String fileName, int size) { private boolean tryToDelete(BufferContext context) { try { - Files.delete(context.file.toPath()); - if (LOGGER.isInfoEnabled()) { - LOGGER.info("Buffer {} deleted", context.file); + if (context.file != null) { + Files.delete(context.file.toPath()); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Buffer {} deleted", context.file); + } + context.file = null; } - context.file = null; } catch (IOException e) { LOGGER.trace(e.toString(), e); }