You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2010/07/13 16:02:08 UTC
svn commit: r963716 -
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/CanonTestCase.java
Author: kristwaa
Date: Tue Jul 13 14:02:08 2010
New Revision: 963716
URL: http://svn.apache.org/viewvc?rev=963716&view=rev
Log:
DERBY-4732: Release system resources in CanonTestCase thoroughly
Added finally block to clean up resources.
Contributed by Yun Lee (yun dot lee dot bj at gmail dot com).
Patch file: derby-4732.patch
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/CanonTestCase.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/CanonTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/CanonTestCase.java?rev=963716&r1=963715&r2=963716&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/CanonTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/CanonTestCase.java Tue Jul 13 14:02:08 2010
@@ -73,6 +73,9 @@ abstract class CanonTestCase extends Bas
rawBytes.close();
byte[] testRawBytes = rawBytes.toByteArray();
+ rawBytes = null;
+ BufferedReader cannonReader = null;
+ BufferedReader testOutput = null;
try {
URL canonURL = getTestResource(canon);
@@ -80,10 +83,10 @@ abstract class CanonTestCase extends Bas
InputStream canonStream = openTestResource(canonURL);
- BufferedReader cannonReader = new BufferedReader(
+ cannonReader = new BufferedReader(
new InputStreamReader(canonStream, outputEncoding));
- BufferedReader testOutput = new BufferedReader(
+ testOutput = new BufferedReader(
new InputStreamReader(
new ByteArrayInputStream(testRawBytes),
outputEncoding));
@@ -106,12 +109,23 @@ abstract class CanonTestCase extends Bas
assertEquals("Output at line " + lineNumber, canonLine,
testLine);
}
-
- cannonReader.close();
- testOutput.close();
} catch (Throwable t) {
dumpForFail(testRawBytes);
throw t;
+ } finally {
+ if (cannonReader != null) {
+ try {
+ cannonReader.close();
+ } catch (IOException e) {
+ }
+ }
+
+ if (testOutput != null) {
+ try {
+ testOutput.close();
+ } catch (IOException e) {
+ }
+ }
}
}
@@ -141,9 +155,4 @@ abstract class CanonTestCase extends Bas
outStream.flush();
outStream.close();
}
-
- protected void tearDown() throws Exception {
- rawBytes = null;
- super.tearDown();
- }
}