Browse Source

YamlProcessor defensively closes InputStream

Issue: SPR-12487
pull/701/head
Juergen Hoeller 10 years ago
parent
commit
9a71a0c6c9
  1. 23
      spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java

23
spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.beans.factory.config;
import java.io.IOException;
import java.io.InputStream;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
@ -146,17 +147,23 @@ public abstract class YamlProcessor { @@ -146,17 +147,23 @@ public abstract class YamlProcessor {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Loading from YAML: " + resource);
}
for (Object object : yaml.loadAll(resource.getInputStream())) {
if (object != null && process(asMap(object), callback)) {
count++;
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND) {
break;
InputStream stream = resource.getInputStream();
try {
for (Object object : yaml.loadAll(stream)) {
if (object != null && process(asMap(object), callback)) {
count++;
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND) {
break;
}
}
}
if (this.logger.isDebugEnabled()) {
this.logger.debug("Loaded " + count + " document" + (count > 1 ? "s" : "") +
" from YAML resource: " + resource);
}
}
if (this.logger.isDebugEnabled()) {
this.logger.debug("Loaded " + count + " document" + (count > 1 ? "s" : "") +
" from YAML resource: " + resource);
finally {
stream.close();
}
}
catch (IOException ex) {

Loading…
Cancel
Save