Use try-with-resource in XmlBeanDefinitionReader

Closes gh-24492
This commit is contained in:
Rossen Stoyanchev 2020-02-20 17:28:15 +00:00
parent 96e77d417b
commit 97ba00eff2
1 changed files with 7 additions and 12 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -327,18 +327,13 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
throw new BeanDefinitionStoreException( throw new BeanDefinitionStoreException(
"Detected cyclic loading of " + encodedResource + " - check your import definitions!"); "Detected cyclic loading of " + encodedResource + " - check your import definitions!");
} }
try {
InputStream inputStream = encodedResource.getResource().getInputStream(); try (InputStream inputStream = encodedResource.getResource().getInputStream()) {
try { InputSource inputSource = new InputSource(inputStream);
InputSource inputSource = new InputSource(inputStream); if (encodedResource.getEncoding() != null) {
if (encodedResource.getEncoding() != null) { inputSource.setEncoding(encodedResource.getEncoding());
inputSource.setEncoding(encodedResource.getEncoding());
}
return doLoadBeanDefinitions(inputSource, encodedResource.getResource());
}
finally {
inputStream.close();
} }
return doLoadBeanDefinitions(inputSource, encodedResource.getResource());
} }
catch (IOException ex) { catch (IOException ex) {
throw new BeanDefinitionStoreException( throw new BeanDefinitionStoreException(