From ef480648040714f9f8852aff8ba4ee4a04d82dd3 Mon Sep 17 00:00:00 2001 From: sangyongchoi Date: Mon, 28 Dec 2020 11:10:34 +0900 Subject: [PATCH] change to try with resources --- .../ibatis/builder/xml/XMLConfigBuilder.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java b/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java index 0ba8bdbea7f..bc569265d11 100644 --- a/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java +++ b/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java @@ -372,14 +372,16 @@ private void mapperElement(XNode parent) throws Exception { String mapperClass = child.getStringAttribute("class"); if (resource != null && url == null && mapperClass == null) { ErrorContext.instance().resource(resource); - InputStream inputStream = Resources.getResourceAsStream(resource); - XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments()); - mapperParser.parse(); + try(InputStream inputStream = Resources.getResourceAsStream(resource)) { + XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments()); + mapperParser.parse(); + } } else if (resource == null && url != null && mapperClass == null) { ErrorContext.instance().resource(url); - InputStream inputStream = Resources.getUrlAsStream(url); - XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, url, configuration.getSqlFragments()); - mapperParser.parse(); + try(InputStream inputStream = Resources.getUrlAsStream(url)){ + XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, url, configuration.getSqlFragments()); + mapperParser.parse(); + } } else if (resource == null && url == null && mapperClass != null) { Class mapperInterface = Resources.classForName(mapperClass); configuration.addMapper(mapperInterface);