[JGIT PATCH 7/8] Close files opened by unit testing framework

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx>
---
 .../org/spearce/jgit/lib/RepositoryTestCase.java   |   12 ++++++++----
 .../tst/org/spearce/jgit/lib/T0007_Index.java      |   10 +++++++---
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
index aaa3592..376a76e 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
@@ -165,10 +165,14 @@ protected File writeTrashFile(final String name, final String data)
 	protected static void checkFile(File f, final String checkData)
 			throws IOException {
 		Reader r = new InputStreamReader(new FileInputStream(f), "ISO-8859-1");
-		char[] data = new char[(int) f.length()];
-		if (f.length() !=  r.read(data))
-			throw new IOException("Internal error reading file data from "+f);
-		assertEquals(checkData, new String(data));
+		try {
+			char[] data = new char[(int) f.length()];
+			if (f.length() !=  r.read(data))
+				throw new IOException("Internal error reading file data from "+f);
+			assertEquals(checkData, new String(data));
+		} finally {
+			r.close();
+		}
 	}
 
 	protected Repository db;
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0007_Index.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0007_Index.java
index 69f3a48..499812e 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0007_Index.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0007_Index.java
@@ -424,9 +424,13 @@ public void test031_executeBit_coreModeFalse() throws IllegalArgumentException, 
 	private String content(File f) throws IOException {
 		byte[] buf = new byte[(int) f.length()];
 		FileInputStream is = new FileInputStream(f);
-		int read = is.read(buf);
-		assertEquals(f.length(), read);
-		return new String(buf, 0);
+		try {
+			int read = is.read(buf);
+			assertEquals(f.length(), read);
+			return new String(buf, 0);
+		} finally {
+			is.close();
+		}
 	}
 
 	private void delete(File f) throws IOException {
-- 
1.6.0.3.640.g6331a

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux