This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-logging.git
commit 7af5ec6b037bc281713eb7174c252bb3a16e9b63 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Nov 19 11:41:57 2023 -0500 Use try-with-resources --- .../org/apache/commons/logging/LogFactory.java | 40 ++++++++-------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/apache/commons/logging/LogFactory.java b/src/main/java/org/apache/commons/logging/LogFactory.java index 324e6ff..df81201 100644 --- a/src/main/java/org/apache/commons/logging/LogFactory.java +++ b/src/main/java/org/apache/commons/logging/LogFactory.java @@ -996,42 +996,32 @@ public abstract class LogFactory { * {@code Null} is returned if the URL cannot be opened. */ private static Properties getProperties(final URL url) { - final PrivilegedAction<Properties> action = () -> { - InputStream stream = null; + return AccessController.doPrivileged((PrivilegedAction<Properties>) () -> { + // We must ensure that useCaches is set to false, as the + // default behavior of java is to cache file handles, and + // this "locks" files, preventing hot-redeploy on windows. try { - // We must ensure that useCaches is set to false, as the - // default behavior of java is to cache file handles, and - // this "locks" files, preventing hot-redeploy on windows. final URLConnection connection = url.openConnection(); connection.setUseCaches(false); - stream = connection.getInputStream(); - if (stream != null) { - final Properties props = new Properties(); - props.load(stream); - stream.close(); - stream = null; - return props; + try (InputStream stream = connection.getInputStream()) { + if (stream != null) { + final Properties props = new Properties(); + props.load(stream); + return props; + } + } catch (final IOException e) { + if (isDiagnosticsEnabled()) { + logDiagnostic("Unable to close stream for URL " + url); + } } } catch (final IOException e) { if (isDiagnosticsEnabled()) { logDiagnostic("Unable to read URL " + url); } - } finally { - if (stream != null) { - try { - stream.close(); - } catch (final IOException e) { - // ignore exception; this should not happen - if (isDiagnosticsEnabled()) { - logDiagnostic("Unable to close stream for URL " + url); - } - } - } } return null; - }; - return AccessController.doPrivileged(action); + }); } /**