Polish "Properly close input streams when loading key stores"

See gh-25884
This commit is contained in:
Stephane Nicoll
2021-04-08 09:21:46 +02:00
parent 1e3f5c342b
commit 25b7495d8e
7 changed files with 34 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -108,8 +108,8 @@ public class CouchbaseAutoConfiguration {
private KeyStore loadKeyStore(String resource, String keyStorePassword) throws Exception {
KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
URL url = ResourceUtils.getURL(resource);
try (InputStream inputStream = url.openStream()) {
store.load(inputStream, (keyStorePassword != null) ? keyStorePassword.toCharArray() : null);
try (InputStream stream = url.openStream()) {
store.load(stream, (keyStorePassword != null) ? keyStorePassword.toCharArray() : null);
}
return store;
}