Skip to content

Commit b91e2d5

Browse files
authored
Fix NPE when using deprecated Azure settings (#28769)
* Fix NPE when using deprecated Azure settings When someone migrates from 5.6 to 6.x with deprecated settings like: ``` cloud: azure: storage: foo: account: <my_account> key: <my_key> ``` It produces a NPE anytime someone wants to use a repository which name is not `default`. This has been introduced by #23518 when I backported it to 6.x branch. In this case, when we generate an OperationContext, we only try to get azure settings from "normal" `storageSettings` with: ```java this.storageSettings.get(clientName) ``` But in the context of deprecated settings, this returns `null` which causes the NPE just after. This commit adds a check and if no settings are found in the "normal" `storageSettings`, we look at settings from `deprecatedStorageSettings`. The reason I missed it in the 7.0 version (master branch) is because actually `deprecatedStorageSettings` has been removed there already. Also I renamed the `testGetSelectedClientDefault` method to `testGenerateOperationContext` as it was only doing exactly the same thing as `testGetDefaultClientWithPrimaryAndSecondaries`. Closes #28299.
1 parent a1d0220 commit b91e2d5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/storage/AzureStorageServiceImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,13 @@ CloudBlobClient getSelectedClient(String account, LocationMode mode) {
176176
return client;
177177
}
178178

179-
private OperationContext generateOperationContext(String clientName) {
179+
// Package private for testing in 6.x only: not needed anymore after
180+
OperationContext generateOperationContext(String clientName) {
180181
OperationContext context = new OperationContext();
181182
AzureStorageSettings azureStorageSettings = this.storageSettings.get(clientName);
183+
if (azureStorageSettings == null) {
184+
azureStorageSettings = deprecatedStorageSettings.get(clientName);
185+
}
182186

183187
if (azureStorageSettings.getProxy() != null) {
184188
context.setProxy(azureStorageSettings.getProxy());

plugins/repository-azure/src/test/java/org/elasticsearch/cloud/azure/storage/AzureStorageServiceTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,11 @@ public void testGetDefaultClientWithPrimaryAndSecondaries() {
390390
}
391391

392392
@Deprecated
393-
public void testGetSelectedClientDefault() {
393+
public void testGenerateOperationContext() {
394394
AzureStorageServiceImpl azureStorageService = new AzureStorageServiceMock(deprecatedSettings);
395-
CloudBlobClient client = azureStorageService.getSelectedClient("default", LocationMode.PRIMARY_ONLY);
396-
assertThat(client.getEndpoint(), is(URI.create("https://azure1")));
395+
// This was producing a NPE when calling any operation with deprecated settings.
396+
// See https://github.com/elastic/elasticsearch/issues/28299
397+
azureStorageService.generateOperationContext("default");
397398
assertDeprecatedWarnings();
398399
}
399400

0 commit comments

Comments
 (0)