Skip to content

Commit 5e2a954

Browse files
authored
Merge pull request #2145 from sangyongchoi/input-stream-close
change to try with resources
2 parents 27848c0 + ef48064 commit 5e2a954

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,16 @@ private void mapperElement(XNode parent) throws Exception {
372372
String mapperClass = child.getStringAttribute("class");
373373
if (resource != null && url == null && mapperClass == null) {
374374
ErrorContext.instance().resource(resource);
375-
InputStream inputStream = Resources.getResourceAsStream(resource);
376-
XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());
377-
mapperParser.parse();
375+
try(InputStream inputStream = Resources.getResourceAsStream(resource)) {
376+
XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());
377+
mapperParser.parse();
378+
}
378379
} else if (resource == null && url != null && mapperClass == null) {
379380
ErrorContext.instance().resource(url);
380-
InputStream inputStream = Resources.getUrlAsStream(url);
381-
XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, url, configuration.getSqlFragments());
382-
mapperParser.parse();
381+
try(InputStream inputStream = Resources.getUrlAsStream(url)){
382+
XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, url, configuration.getSqlFragments());
383+
mapperParser.parse();
384+
}
383385
} else if (resource == null && url == null && mapperClass != null) {
384386
Class<?> mapperInterface = Resources.classForName(mapperClass);
385387
configuration.addMapper(mapperInterface);

0 commit comments

Comments
 (0)