Skip to content

Commit eebb13c

Browse files
rolnicoyojvr
authored andcommitted
Fix potential NPE in MmapByteBufferService (powsybl#181)
* 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]>
1 parent 49c52f9 commit eebb13c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

metrix-mapping/src/main/java/com/powsybl/metrix/mapping/timeseries/MmapByteBufferService.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@
3535
/**
3636
* Memory mapped file buffer allocation service.
3737
* Main purpose of this utility class is to overcome a Java issue on Windows with memory mapped file.
38-
* Once Random access file is closed, file cannot be delete until buffer has been garbage collected.
38+
* Once Random access file is closed, file cannot be deleted until buffer has been garbage collected.
3939
* The workaround used here is to start a "cleaner" thread that try to delete the file every minute.
40-
*/
41-
/**
40+
*
4241
* @author Paul Bui-Quang {@literal <paul.buiquang at rte-france.com>}
4342
*/
4443

@@ -119,11 +118,13 @@ public ByteBuffer create(String fileName, int size) {
119118

120119
private boolean tryToDelete(BufferContext context) {
121120
try {
122-
Files.delete(context.file.toPath());
123-
if (LOGGER.isInfoEnabled()) {
124-
LOGGER.info("Buffer {} deleted", context.file);
121+
if (context.file != null) {
122+
Files.delete(context.file.toPath());
123+
if (LOGGER.isInfoEnabled()) {
124+
LOGGER.info("Buffer {} deleted", context.file);
125+
}
126+
context.file = null;
125127
}
126-
context.file = null;
127128
} catch (IOException e) {
128129
LOGGER.trace(e.toString(), e);
129130
}

0 commit comments

Comments
 (0)