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-net.git
commit 676aa83dd768ee2fd8463a497e15b4f1e802c000 Author: Gary D. Gregory <[email protected]> AuthorDate: Sun Mar 16 09:08:08 2025 -0400 KeyManagerUtils.loadStore(String, File, String) shouldn't ignore an IOException closing a keystore stream Use try-with-resources --- src/changes/changes.xml | 1 + .../java/org/apache/commons/net/util/KeyManagerUtils.java | 12 +++--------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 338e4cfc..e7e96ef0 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -88,6 +88,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="fix" dev="ggregory" due-to="Gary Gregory">FTPClientExample uses the wrong FTP system type to parse file lines.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">Base64 does not call super.finalize().</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">TFTPServer does not call super.finalize().</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">KeyManagerUtils.loadStore(String, File, String) shouldn't ignore an IOException closing a keystore stream; use try-with-resources.</action> <!-- ADD --> <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.net.nntp.Article#getChild().</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.net.nntp.Article#getNext().</action> diff --git a/src/main/java/org/apache/commons/net/util/KeyManagerUtils.java b/src/main/java/org/apache/commons/net/util/KeyManagerUtils.java index b1fa3ab7..0ecda9e5 100644 --- a/src/main/java/org/apache/commons/net/util/KeyManagerUtils.java +++ b/src/main/java/org/apache/commons/net/util/KeyManagerUtils.java @@ -20,6 +20,7 @@ package org.apache.commons.net.util; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.net.Socket; import java.security.GeneralSecurityException; import java.security.KeyStore; @@ -34,8 +35,6 @@ import java.util.Enumeration; import javax.net.ssl.KeyManager; import javax.net.ssl.X509ExtendedKeyManager; -import org.apache.commons.io.IOUtils; - /** * General KeyManager utilities * <p> @@ -213,15 +212,10 @@ public final class KeyManagerUtils { throw new KeyStoreException("Cannot find a private key entry"); } - private static KeyStore loadStore(final String storeType, final File storePath, final String storePass) - throws KeyStoreException, IOException, GeneralSecurityException { + private static KeyStore loadStore(final String storeType, final File storePath, final String storePass) throws IOException, GeneralSecurityException { final KeyStore ks = KeyStore.getInstance(storeType); - FileInputStream stream = null; - try { - stream = new FileInputStream(storePath); + try (InputStream stream = new FileInputStream(storePath)) { ks.load(stream, storePass.toCharArray()); - } finally { - IOUtils.closeQuietly(stream); } return ks; }
