You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by tb...@apache.org on 2015/07/18 16:07:09 UTC
svn commit: r1691731 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java
Author: tboehme
Date: Sat Jul 18 14:07:09 2015
New Revision: 1691731
URL: http://svn.apache.org/r1691731
Log:
PDFBOX-2882: reworked ScratchFile.close to run completely even in case of an exception; don't free in-memory pages
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java?rev=1691731&r1=1691730&r2=1691731&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java Sat Jul 18 14:07:09 2015
@@ -218,6 +218,7 @@ public class ScratchFile implements Clos
{
if ((pageIdx < 0) || (pageIdx >= pageCount))
{
+ checkClosed();
throw new IOException("Page index out of range: " + pageIdx + ". Max value: " + (pageCount - 1) );
}
@@ -269,6 +270,7 @@ public class ScratchFile implements Clos
{
if ((pageIdx<0) || (pageIdx>=pageCount))
{
+ checkClosed();
throw new IOException("Page index out of range: " + pageIdx + ". Max value: " + (pageCount - 1) );
}
@@ -363,24 +365,31 @@ public class ScratchFile implements Clos
public void close() throws IOException
{
isClosed = true;
+
+ IOException ioexc = null;
synchronized (ioLock)
{
if (raf != null)
{
- raf.close();
- raf = null;
+ try
+ {
+ raf.close();
+ }
+ catch (IOException ioe)
+ {
+ ioexc = ioe;
+ }
}
if (file != null)
{
- if (file.delete())
+ if (!file.delete())
{
- file = null;
- }
- else
- {
- throw new IOException("Error deleting scratch file: " + file.getAbsolutePath());
+ if (file.exists() && (ioexc == null))
+ {
+ ioexc = new IOException("Error deleting scratch file: " + file.getAbsolutePath());
+ }
}
}
}
@@ -392,9 +401,9 @@ public class ScratchFile implements Clos
pageCount = 0;
}
- for (int pIdx = 0; pIdx < inMemoryMaxPageCount; pIdx++)
+ if (ioexc != null)
{
- inMemoryPages[pIdx] = null;
+ throw ioexc;
}
}
}