Skip to content

Commit e0e8b65

Browse files
committed
PDFBOX-5660: skip close operations for already closed resources as proposed by Valery Bokov, closes #287
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1929105 13f79535-47bb-0310-9956-ffa450edef68
1 parent eebaf10 commit e0e8b65

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

io/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,13 @@ private RandomAccessReadBuffer(RandomAccessReadBuffer parent)
150150
@Override
151151
public void close() throws IOException
152152
{
153-
rarbCopies.values().forEach(IOUtils::closeQuietly);
154-
rarbCopies.clear();
155-
currentBuffer = null;
156-
bufferList.clear();
153+
if (!isClosed())
154+
{
155+
rarbCopies.values().forEach(IOUtils::closeQuietly);
156+
rarbCopies.clear();
157+
currentBuffer = null;
158+
bufferList.clear();
159+
}
157160
}
158161

159162
/**

io/src/main/java/org/apache/pdfbox/io/RandomAccessReadBufferedFile.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,14 @@ public long length() throws IOException
242242
@Override
243243
public void close() throws IOException
244244
{
245-
rafCopies.values().forEach(IOUtils::closeQuietly);
246-
rafCopies.clear();
247-
fileChannel.close();
248-
pageCache.clear();
249-
isClosed = true;
245+
if (!isClosed())
246+
{
247+
rafCopies.values().forEach(IOUtils::closeQuietly);
248+
rafCopies.clear();
249+
fileChannel.close();
250+
pageCache.clear();
251+
isClosed = true;
252+
}
250253
}
251254

252255
@Override

io/src/main/java/org/apache/pdfbox/io/RandomAccessReadMemoryMappedFile.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ private RandomAccessReadMemoryMappedFile(RandomAccessReadMemoryMappedFile parent
107107
@Override
108108
public void close() throws IOException
109109
{
110+
if (isClosed())
111+
{
112+
return;
113+
}
110114
if (fileChannel != null)
111115
{
112116
fileChannel.close();

0 commit comments

Comments
 (0)