diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2018-03-13 16:11:40 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2018-03-15 06:39:57 +0900 |
commit | 3e1066d0a4460c63b7d77293959c6e548bef9a16 (patch) | |
tree | f468870902e969f396cfb5c922579ff1dd0d2bc6 /org.eclipse.jgit/src/org/eclipse/jgit/dircache | |
parent | aa563091d5454909d46b3426e872a0f57892c578 (diff) | |
download | jgit-3e1066d0a4460c63b7d77293959c6e548bef9a16.tar.gz jgit-3e1066d0a4460c63b7d77293959c6e548bef9a16.zip |
Add SilentFileInputStream to allow ignoring exceptions raised by close()
There are several cases where a FileInputStream is opened outside of
a try-with-resource because we want to explicitly close it and ignore
any IOException that is raised by the close() method.
Introduce a helper class, SilentFileInputStream, that overrides the
close method and ignores the exceptions. This allows to open the stream
in a try-with-resource block and remove the explicit handling of the
close method.
Change-Id: I8612f948a1a5b3d1031344922ad75ce4492cfc61
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/dircache')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java index cc431dbdf2..fcee252f80 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java @@ -49,7 +49,6 @@ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.EOFException; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -87,6 +86,7 @@ import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.MutableInteger; import org.eclipse.jgit.util.NB; import org.eclipse.jgit.util.TemporaryBuffer; +import org.eclipse.jgit.util.io.SilentFileInputStream; /** * Support for the Git dircache (aka index file). @@ -429,18 +429,10 @@ public class DirCache { if (!liveFile.exists()) clear(); else if (snapshot == null || snapshot.isModified(liveFile)) { - try { - final FileInputStream inStream = new FileInputStream(liveFile); - try { - clear(); - readFrom(inStream); - } finally { - try { - inStream.close(); - } catch (IOException err2) { - // Ignore any close failures. - } - } + try (SilentFileInputStream inStream = new SilentFileInputStream( + liveFile)) { + clear(); + readFrom(inStream); } catch (FileNotFoundException fnfe) { if (liveFile.exists()) { // Panic: the index file exists but we can't read it |