Skip to content

Commit

Permalink
Fix potential NPE in MmapByteBufferService (#181)
Browse files Browse the repository at this point in the history
* fix potential NPE

Signed-off-by: Nicolas Rol <[email protected]>

* back to catching IOException

Signed-off-by: Nicolas Rol <[email protected]>

---------

Signed-off-by: Nicolas Rol <[email protected]>
(cherry picked from commit 21929f8)
  • Loading branch information
rolnico committed Nov 7, 2024
1 parent 45f08f5 commit f4670aa
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <paul.buiquang at rte-france.com>}
*/

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit f4670aa

Please sign in to comment.