Browse Source

Use try-with-resource in XmlBeanDefinitionReader

Closes gh-24492
pull/24572/head
Rossen Stoyanchev 5 years ago
parent
commit
97ba00eff2
  1. 19
      spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java

19
spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -327,18 +327,13 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader { @@ -327,18 +327,13 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
throw new BeanDefinitionStoreException(
"Detected cyclic loading of " + encodedResource + " - check your import definitions!");
}
try {
InputStream inputStream = encodedResource.getResource().getInputStream();
try {
InputSource inputSource = new InputSource(inputStream);
if (encodedResource.getEncoding() != null) {
inputSource.setEncoding(encodedResource.getEncoding());
}
return doLoadBeanDefinitions(inputSource, encodedResource.getResource());
}
finally {
inputStream.close();
try (InputStream inputStream = encodedResource.getResource().getInputStream()) {
InputSource inputSource = new InputSource(inputStream);
if (encodedResource.getEncoding() != null) {
inputSource.setEncoding(encodedResource.getEncoding());
}
return doLoadBeanDefinitions(inputSource, encodedResource.getResource());
}
catch (IOException ex) {
throw new BeanDefinitionStoreException(

Loading…
Cancel
Save