Change this "try" to a try-with-resources

Closes gh-1671
This commit is contained in:
igor-suhorukov
2018-02-09 01:00:24 +03:00
committed by Stephane Nicoll
parent 909cacec42
commit c0b4b5787f
5 changed files with 15 additions and 37 deletions

View File

@@ -461,9 +461,8 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
* @throws IOException if properties loading failed
*/
protected Properties loadProperties(Resource resource, String filename) throws IOException {
InputStream is = resource.getInputStream();
Properties props = newProperties();
try {
try (InputStream is = resource.getInputStream()) {
String resourceFilename = resource.getFilename();
if (resourceFilename != null && resourceFilename.endsWith(XML_SUFFIX)) {
if (logger.isDebugEnabled()) {
@@ -494,9 +493,6 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
}
return props;
}
finally {
is.close();
}
}
/**

View File

@@ -26,7 +26,6 @@ import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
@@ -370,11 +369,8 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
if (encoding == null) {
encoding = "ISO-8859-1";
}
try {
return loadBundle(new InputStreamReader(stream, encoding));
}
finally {
stream.close();
try (InputStreamReader bundleReader = new InputStreamReader(stream, encoding)) {
return loadBundle(bundleReader);
}
}
else {