From 960d7d03b0dd7d1070ff218d5b27d21db7b0f0da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=BChne?= Date: Sat, 11 Jan 2003 07:39:48 +0000 Subject: [PATCH] close cachefile streams, fixes bug #665016 --- .../tools/checkstyle/PropertyCacheFile.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java index d3001e31c..cc15a5056 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java @@ -65,8 +65,10 @@ class PropertyCacheFile boolean setInActive = true; final String fileName = aFileName; if (fileName != null) { + FileInputStream inStream = null; try { - mDetails.load(new FileInputStream(fileName)); + inStream = new FileInputStream(fileName); + mDetails.load(inStream); String cachedConfigHash = mDetails.getProperty(CONFIG_HASH_KEY); String currentConfigHash = getConfigHashCode(aCurrentConfig); setInActive = false; @@ -87,6 +89,18 @@ class PropertyCacheFile System.out.println("Unable to open cache file, ignoring."); e.printStackTrace(System.out); } + finally { + if (inStream != null) { + try { + inStream.close(); + } + catch (IOException ex) { + // TODO: use logger + System.out.println("Unable to close cache file."); + ex.printStackTrace(System.out); + } + } + } } mDetailsFile = (setInActive) ? null : fileName; } @@ -95,13 +109,27 @@ class PropertyCacheFile void destroy() { if (mDetailsFile != null) { + FileOutputStream out = null; try { - mDetails.store(new FileOutputStream(mDetailsFile), null); + out = new FileOutputStream(mDetailsFile); + mDetails.store(out, null); } catch (IOException e) { System.out.println("Unable to save cache file"); e.printStackTrace(System.out); } + finally { + if (out != null) { + try { + out.flush(); + out.close(); + } + catch (IOException ex) { + System.out.println("Unable to close cache file"); + ex.printStackTrace(System.out); + } + } + } } }