You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2023/04/13 06:29:00 UTC
[jira] [Commented] (PDFBOX-5586) NullPointerException when closing RandomAccessReadMemoryMappedFile more than once
[ https://issues.apache.org/jira/browse/PDFBOX-5586?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17711704#comment-17711704 ]
ASF subversion and git services commented on PDFBOX-5586:
---------------------------------------------------------
Commit 1909115 from lehmi@apache.org in branch 'pdfbox/trunk'
[ https://svn.apache.org/r1909115 ]
PDFBOX-5586: added null checks based on a proposal by Matt Bamberger
> 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
> Priority: Major
> Fix For: 3.0.0 PDFBox
>
>
> Matt Bamberger posted an error on users@pdfbox.a.o
> {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: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org