Ensure LineNumberReader is always closed
Wrap ResourceDatabasePopulator.readScript() code in a try/finally block to ensure that the LineNumberReader is always closed. Issue: SPR-9912
This commit is contained in:
parent
073b627f4e
commit
33abee2db2
|
|
@ -224,20 +224,24 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
|||
*/
|
||||
private String readScript(EncodedResource resource) throws IOException {
|
||||
LineNumberReader lnr = new LineNumberReader(resource.getReader());
|
||||
String currentStatement = lnr.readLine();
|
||||
StringBuilder scriptBuilder = new StringBuilder();
|
||||
while (currentStatement != null) {
|
||||
if (StringUtils.hasText(currentStatement) &&
|
||||
(this.commentPrefix != null && !currentStatement.startsWith(this.commentPrefix))) {
|
||||
if (scriptBuilder.length() > 0) {
|
||||
scriptBuilder.append('\n');
|
||||
try {
|
||||
String currentStatement = lnr.readLine();
|
||||
StringBuilder scriptBuilder = new StringBuilder();
|
||||
while (currentStatement != null) {
|
||||
if (StringUtils.hasText(currentStatement)
|
||||
&& (this.commentPrefix != null && !currentStatement.startsWith(this.commentPrefix))) {
|
||||
if (scriptBuilder.length() > 0) {
|
||||
scriptBuilder.append('\n');
|
||||
}
|
||||
scriptBuilder.append(currentStatement);
|
||||
}
|
||||
scriptBuilder.append(currentStatement);
|
||||
currentStatement = lnr.readLine();
|
||||
}
|
||||
currentStatement = lnr.readLine();
|
||||
maybeAddSeparatorToScript(scriptBuilder);
|
||||
return scriptBuilder.toString();
|
||||
} finally {
|
||||
lnr.close();
|
||||
}
|
||||
maybeAddSeparatorToScript(scriptBuilder);
|
||||
return scriptBuilder.toString();
|
||||
}
|
||||
|
||||
private void maybeAddSeparatorToScript(StringBuilder scriptBuilder) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue