From: Shawn O. Pearce Date: Tue, 21 Apr 2009 01:21:03 GMT Subject: [JGIT PATCH 01/10] Safely handle closing an already closed WindowedFile Message-ID: <1240276872-17893-2-git-send-email-spearce@spearce.org> In-Reply-To: <1240276872-17893-1-git-send-email-spearce@spearce.org> If cacheOpen throws an exception (e.g. FileNotFoundException) we may wind up in cacheClose, where the fd is null because we didn't successfully construct the RandomAccessFile. In such cases there is nothing to attempt to close. Signed-off-by: Shawn O. Pearce --- .../src/org/spearce/jgit/lib/WindowedFile.java | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java index 938f44c..9293eb9 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java @@ -297,14 +297,16 @@ void cacheOpen() throws IOException { } void cacheClose() { - try { - fd.close(); - } catch (IOException err) { - // Ignore a close event. We had it open only for reading. - // There should not be errors related to network buffers - // not flushed, etc. + if (fd != null) { + try { + fd.close(); + } catch (IOException err) { + // Ignore a close event. We had it open only for reading. + // There should not be errors related to network buffers + // not flushed, etc. + } + fd = null; } - fd = null; } void allocWindow(final WindowCursor curs, final int windowId, -- 1.6.3.rc1.188.ga02b