diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java index 9f6cc4ebc60b..5084da8b97a2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.couchbase; +import java.io.InputStream; import java.net.URL; import java.security.KeyStore; @@ -114,7 +115,9 @@ private TrustManagerFactory getTrustManagerFactory(CouchbaseProperties.Ssl ssl) private KeyStore loadKeyStore(String resource, String keyStorePassword) throws Exception { KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType()); URL url = ResourceUtils.getURL(resource); - store.load(url.openStream(), (keyStorePassword != null) ? keyStorePassword.toCharArray() : null); + try (InputStream inputStream = url.openStream()) { + store.load(inputStream, (keyStorePassword != null) ? keyStorePassword.toCharArray() : null); + } return store; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/SslServerCustomizer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/SslServerCustomizer.java index eeab11a5f926..f9123a70ec51 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/SslServerCustomizer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/SslServerCustomizer.java @@ -16,6 +16,7 @@ package org.springframework.boot.web.embedded.netty; +import java.io.InputStream; import java.net.Socket; import java.net.URL; import java.security.InvalidAlgorithmParameterException; @@ -170,7 +171,9 @@ private KeyStore loadStore(String type, String provider, String resource, String KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type); try { URL url = ResourceUtils.getURL(resource); - store.load(url.openStream(), (password != null) ? password.toCharArray() : null); + try (InputStream inputStream = url.openStream()) { + store.load(inputStream, (password != null) ? password.toCharArray() : null); + } return store; } catch (Exception ex) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/SslBuilderCustomizer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/SslBuilderCustomizer.java index 65c948be88b8..434448c67046 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/SslBuilderCustomizer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/SslBuilderCustomizer.java @@ -16,6 +16,7 @@ package org.springframework.boot.web.embedded.undertow; +import java.io.InputStream; import java.net.InetAddress; import java.net.Socket; import java.net.URL; @@ -181,7 +182,9 @@ private KeyStore loadStore(String type, String provider, String resource, String KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type); try { URL url = ResourceUtils.getURL(resource); - store.load(url.openStream(), (password != null) ? password.toCharArray() : null); + try (InputStream inputStream = url.openStream()) { + store.load(inputStream, (password != null) ? password.toCharArray() : null); + } return store; } catch (Exception ex) {