1717package org .springframework .amqp .rabbit .connection ;
1818
1919import java .io .IOException ;
20+ import java .io .InputStream ;
2021import java .net .URI ;
2122import java .net .URISyntaxException ;
2223import java .security .KeyManagementException ;
@@ -773,7 +774,9 @@ protected KeyManager[] configureKeyManagers() throws KeyStoreException, IOExcept
773774 Resource resource = this .keyStoreResource != null ? this .keyStoreResource
774775 : this .resolver .getResource (keyStoreName );
775776 KeyStore ks = KeyStore .getInstance (storeType );
776- ks .load (resource .getInputStream (), keyPassphrase );
777+ try (InputStream inputStream = resource .getInputStream ()) {
778+ ks .load (inputStream , keyPassphrase );
779+ }
777780 KeyManagerFactory kmf = KeyManagerFactory .getInstance (this .keyStoreAlgorithm );
778781 kmf .init (ks , keyPassphrase );
779782 keyManagers = kmf .getKeyManagers ();
@@ -796,7 +799,9 @@ protected TrustManager[] configureTrustManagers()
796799 Resource resource = this .trustStoreResource != null ? this .trustStoreResource
797800 : this .resolver .getResource (trustStoreName );
798801 KeyStore tks = KeyStore .getInstance (storeType );
799- tks .load (resource .getInputStream (), trustPassphrase );
802+ try (InputStream inputStream = resource .getInputStream ()) {
803+ tks .load (inputStream , trustPassphrase );
804+ }
800805 TrustManagerFactory tmf = TrustManagerFactory .getInstance (this .trustStoreAlgorithm );
801806 tmf .init (tks );
802807 trustManagers = tmf .getTrustManagers ();
0 commit comments