Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential NPE in MmapByteBufferService #181

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 +118,14 @@ 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) {
} catch (Exception e) {
LOGGER.trace(e.toString(), e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (Exception e) {
LOGGER.trace(e.toString(), e);
} catch (IOException e) {
throw new UncheckedIOException(e);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for the IOException but we don't want to throw an exception if we fail to delete the file, just log it and return false

}
if (context.file != null) {
Expand Down
Loading