提交 263dd559 编写于 作者: J Juergen Hoeller

SimpleJdbcTestUtils executeSqlScript properly closes its LineNumberReader after use (SPR-8872)

上级 d10f2258
......@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.EncodedResource;
......@@ -134,9 +135,10 @@ public abstract class SimpleJdbcTestUtils {
long startTime = System.currentTimeMillis();
List<String> statements = new LinkedList<String>();
LineNumberReader reader = null;
try {
LineNumberReader lnr = new LineNumberReader(resource.getReader());
String script = JdbcTestUtils.readScript(lnr);
reader = new LineNumberReader(resource.getReader());
String script = JdbcTestUtils.readScript(reader);
char delimiter = ';';
if (!JdbcTestUtils.containsSqlScriptDelimiters(script, delimiter)) {
delimiter = '\n';
......@@ -168,6 +170,17 @@ public abstract class SimpleJdbcTestUtils {
catch (IOException ex) {
throw new DataAccessResourceFailureException("Failed to open SQL script from " + resource, ex);
}
finally {
try {
if (reader != null) {
reader.close();
}
}
catch (IOException ex) {
// ignore
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册