提交 c23bb0ed authored 作者: Noel Grandin's avatar Noel Grandin

close a couple of resource leaks

上级 c1087334
...@@ -11,7 +11,6 @@ import java.io.LineNumberReader; ...@@ -11,7 +11,6 @@ import java.io.LineNumberReader;
import java.sql.Connection; import java.sql.Connection;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.ScriptReader; import org.h2.util.ScriptReader;
...@@ -43,7 +42,7 @@ public class TestScriptSimple extends TestBase { ...@@ -43,7 +42,7 @@ public class TestScriptSimple extends TestBase {
InputStream is = getClass().getClassLoader().getResourceAsStream(inFile); InputStream is = getClass().getClassLoader().getResourceAsStream(inFile);
LineNumberReader lineReader = new LineNumberReader( LineNumberReader lineReader = new LineNumberReader(
new InputStreamReader(is, "Cp1252")); new InputStreamReader(is, "Cp1252"));
ScriptReader reader = new ScriptReader(lineReader); try (ScriptReader reader = new ScriptReader(lineReader)) {
while (true) { while (true) {
String sql = reader.readStatement(); String sql = reader.readStatement();
if (sql == null) { if (sql == null) {
...@@ -70,7 +69,7 @@ public class TestScriptSimple extends TestBase { ...@@ -70,7 +69,7 @@ public class TestScriptSimple extends TestBase {
throw e; throw e;
} }
} }
is.close(); }
conn.close(); conn.close();
deleteDb("scriptSimple"); deleteDb("scriptSimple");
} }
......
...@@ -46,7 +46,7 @@ public class TestScriptReader extends TestBase { ...@@ -46,7 +46,7 @@ public class TestScriptReader extends TestBase {
} }
String s = buff.toString(); String s = buff.toString();
StringReader reader = new StringReader(s); StringReader reader = new StringReader(s);
ScriptReader source = new ScriptReader(reader); try (ScriptReader source = new ScriptReader(reader)) {
for (int j = 0; j < l; j++) { for (int j = 0; j < l; j++) {
String e = source.readStatement(); String e = source.readStatement();
String c = sql[j]; String c = sql[j];
...@@ -58,6 +58,7 @@ public class TestScriptReader extends TestBase { ...@@ -58,6 +58,7 @@ public class TestScriptReader extends TestBase {
assertEquals(null, source.readStatement()); assertEquals(null, source.readStatement());
} }
} }
}
private static String randomStatement(Random random) { private static String randomStatement(Random random) {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论