From 52b95f1c48e84eaaca934d8b0504734fd52fc9bf Mon Sep 17 00:00:00 2001 From: Adrian Cumiskey Date: Tue, 22 Jul 2008 09:44:49 +0000 Subject: [PATCH] Added a finalize() just in case a problem occurs during rendering and close() never gets called. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@678694 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/afp/DataObjectCache.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/fop/render/afp/DataObjectCache.java b/src/java/org/apache/fop/render/afp/DataObjectCache.java index ee684db6f..85b96eff8 100644 --- a/src/java/org/apache/fop/render/afp/DataObjectCache.java +++ b/src/java/org/apache/fop/render/afp/DataObjectCache.java @@ -109,17 +109,33 @@ public final class DataObjectCache { */ public void clear() { try { - raFile.close(); - tempFile.delete(); + if (raFile != null) { + raFile.close(); + raFile = null; + } + if (tempFile != null) { + tempFile.delete(); + tempFile = null; + } } catch (IOException e) { - log.error("Failed to close temporary file: " + e.getMessage()); + log.error("Failed to close/delete temporary file: " + e.getMessage()); } finally { synchronized (cacheMap) { - cacheMap.remove(id); // remove ourselves from the cache map + // remove ourselves from the cache map + cacheMap.remove(id); } } } + /** {@inheritDoc} */ + public void finalize() throws Throwable { + try { + clear(); + } finally { + super.finalize(); + } + } + /** * Stores a named data object in the cache * -- 2.39.5