Andreas Lehmkühler created PDFBOX-5586:
------------------------------------------
Summary: NullPointerException when closing
RandomAccessReadMemoryMappedFile more than once
Key: PDFBOX-5586
URL: https://issues.apache.org/jira/browse/PDFBOX-5586
Project: PDFBox
Issue Type: Bug
Components: IO
Affects Versions: 3.0.0 PDFBox
Reporter: Andreas Lehmkühler
Assignee: Andreas Lehmkühler
Fix For: 3.0.0 PDFBox
Matt Bamberger posted an error on [email protected]
{quote}
I'm using pdfbox 3.0.0-alpha3
When I use a RandomAccessReadMemoryMappedFile to load a PDDocument, I get a
NullPointerException when I close it after the PDDocument is closed:
{code}
try (RandomAccessReadMemoryMappedFile reader = new
RandomAccessReadMemoryMappedFile(file)) {
try (PDDocument doc = Loader.loadPDF(reader, null, null, null, null)) {
// ...
}
}
{code}
I found that it's because this.mappedByteBuffer is already null the second time
around, so I think you can just wrap in a not-null check:
{code}
public void close() throws IOException {
if (this.fileChannel != null) {
this.fileChannel.close();
}
if (this.mappedByteBuffer != null) { // add this
Optional.ofNullable(this.unmapper).ifPresent((u) -> {
u.accept(this.mappedByteBuffer); // exception is thrown in here
});
this.mappedByteBuffer = null;
}
}
{code}
{quote}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]