Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Fixed an issue where certain `HttpResponseException.getResponse()` calls could cause a `NullPointerException`. ([#47801](https://github.com/Azure/azure-sdk-for-java/issues/47801))

### Other Changes

## 4.7.4 (2025-10-27)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static <E extends HttpResponseException> Response<Void> swallowExceptionForStatu

HttpResponse httpResponse = httpResponseException.getResponse();

if (httpResponse.getStatusCode() == statusCode) {
if (httpResponse != null && httpResponse.getStatusCode() == statusCode) {
return new SimpleResponse<>(httpResponse.getRequest(), httpResponse.getStatusCode(),
httpResponse.getHeaders(), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Fixed an issue where certain `HttpResponseException.getResponse()` calls could cause a `NullPointerException`. ([#47801](https://github.com/Azure/azure-sdk-for-java/issues/47801))

### Other Changes

## 4.8.4 (2025-10-27)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ private Mono<CertificateOperation> createCertificateActivation(String certificat
* @return A {@link ResourceModifiedException} created from the {@link HttpResponseException}.
*/
static HttpResponseException mapCreateCertificateException(HttpResponseException e) {
return e.getResponse().getStatusCode() == 400
return e.getResponse() != null && e.getResponse().getStatusCode() == 400
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand All @@ -430,7 +430,7 @@ private Mono<PollResponse<CertificateOperation>> certificatePollOperation(String
* @return A {@link ResourceModifiedException} created from the {@link HttpResponseException}.
*/
static HttpResponseException mapGetCertificateOperationException(HttpResponseException e) {
return e.getResponse().getStatusCode() == 400
return e.getResponse() != null && e.getResponse().getStatusCode() == 400
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand Down Expand Up @@ -472,7 +472,7 @@ private Mono<CertificateOperation> certificateCancellationOperation(String certi
}

static HttpResponseException mapUpdateCertificateOperationException(HttpResponseException e) {
return e.getResponse().getStatusCode() == 400
return e.getResponse() != null && e.getResponse().getStatusCode() == 400
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand All @@ -486,7 +486,7 @@ private Mono<KeyVaultCertificateWithPolicy> fetchCertificateOperation(String cer
}

static HttpResponseException mapGetCertificateException(HttpResponseException e) {
return e.getResponse().getStatusCode() == 403
return e.getResponse() != null && e.getResponse().getStatusCode() == 403
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand Down Expand Up @@ -813,7 +813,7 @@ private Mono<DeletedCertificate> deleteCertificateActivation(String certificateN
}

static HttpResponseException mapDeleteCertificateException(HttpResponseException e) {
return e.getResponse().getStatusCode() == 404
return e.getResponse() != null && e.getResponse().getStatusCode() == 404
? new ResourceNotFoundException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand All @@ -825,7 +825,7 @@ private Mono<PollResponse<DeletedCertificate>> deleteCertificatePollOperation(St
.map(binaryData -> new PollResponse<>(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED,
createDeletedCertificate(binaryData.toObject(DeletedCertificateBundle.class))))
.onErrorResume(HttpResponseException.class, e -> {
if (e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
if (e.getResponse() != null && e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
return Mono.just(new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue()));
} else {
Expand Down Expand Up @@ -1021,7 +1021,7 @@ private Mono<PollResponse<KeyVaultCertificateWithPolicy>> recoverDeletedCertific
.map(binaryData -> new PollResponse<>(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED,
createCertificateWithPolicy(binaryData.toObject(CertificateBundle.class))))
.onErrorResume(HttpResponseException.class, e -> {
if (e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
if (e.getResponse() != null && e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
return Mono.just(new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue()));
} else {
Expand Down Expand Up @@ -1167,7 +1167,7 @@ public Mono<Response<KeyVaultCertificateWithPolicy>> restoreCertificateBackupWit
}

static HttpResponseException mapRestoreCertificateException(HttpResponseException e) {
return e.getResponse().getStatusCode() == 400
return e.getResponse() != null && e.getResponse().getStatusCode() == 400
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand Down Expand Up @@ -1523,7 +1523,7 @@ public Mono<Response<CertificatePolicy>> getCertificatePolicyWithResponse(String
}

static HttpResponseException mapGetCertificatePolicyException(HttpResponseException e) {
return e.getResponse().getStatusCode() == 403
return e.getResponse() != null && e.getResponse().getStatusCode() == 403
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand Down Expand Up @@ -2123,7 +2123,7 @@ public Mono<Response<CertificateOperation>> deleteCertificateOperationWithRespon
}

static HttpResponseException mapDeleteCertificateOperationException(HttpResponseException e) {
return e.getResponse().getStatusCode() == 400
return e.getResponse() != null && e.getResponse().getStatusCode() == 400
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ private PollResponse<DeletedCertificate> deleteCertificatePollOperation(String c
.getValue()
.toObject(DeletedCertificateBundle.class)));
} catch (HttpResponseException e) {
if (e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
if (e.getResponse() != null && e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
return new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue());
} else {
Expand Down Expand Up @@ -896,7 +896,7 @@ private PollResponse<KeyVaultCertificateWithPolicy> recoverDeletedCertificatePol
.getValue()
.toObject(CertificateBundle.class)));
} catch (HttpResponseException e) {
if (e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
if (e.getResponse() != null && e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
return new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue());
} else {
Expand Down
2 changes: 2 additions & 0 deletions sdk/keyvault/azure-security-keyvault-keys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Fixed an issue where certain `HttpResponseException.getResponse()` calls could cause a `NullPointerException`. ([#47801](https://github.com/Azure/azure-sdk-for-java/issues/47801))

### Other Changes

## 4.10.4 (2025-10-27)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public Mono<Response<KeyVaultKey>> createKeyWithResponse(CreateKeyOptions create
}

static HttpResponseException mapCreateKeyException(HttpResponseException e) {
return (e.getResponse().getStatusCode() == 400)
return (e.getResponse() != null && e.getResponse().getStatusCode() == 400)
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand Down Expand Up @@ -983,7 +983,7 @@ public Mono<Response<KeyVaultKey>> getKeyWithResponse(String name, String versio
* @return The {@link HttpResponseException} that maps from the {@link HttpResponseException}.
*/
static HttpResponseException mapGetKeyException(HttpResponseException e) {
return e.getResponse().getStatusCode() == 403
return e.getResponse() != null && e.getResponse().getStatusCode() == 403
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand Down Expand Up @@ -1177,7 +1177,7 @@ private Function<PollingContext<DeletedKey>, Mono<PollResponse<DeletedKey>>> del
.map(response -> new PollResponse<>(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED,
createDeletedKey(response.getValue().toObject(DeletedKeyBundle.class))))
.onErrorResume(HttpResponseException.class, e -> {
if (e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
if (e.getResponse() != null && e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
return Mono.just(new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue()));
} else {
Expand Down Expand Up @@ -1364,7 +1364,7 @@ private Function<PollingContext<KeyVaultKey>, Mono<KeyVaultKey>> recoverActivati
.map(response -> new PollResponse<>(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED,
createKeyVaultKey(response.getValue().toObject(KeyBundle.class))))
.onErrorResume(HttpResponseException.class, e -> {
if (e.getResponse().getStatusCode() == 404) {
if (e.getResponse() != null && e.getResponse().getStatusCode() == 404) {
return Mono.just(new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue()));
} else {
Expand Down Expand Up @@ -1548,7 +1548,7 @@ public Mono<Response<KeyVaultKey>> restoreKeyBackupWithResponse(byte[] backup) {
}

static HttpResponseException mapRestoreKeyException(HttpResponseException e) {
return (e.getResponse().getStatusCode() == 400)
return (e.getResponse() != null && e.getResponse().getStatusCode() == 400)
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ private Function<PollingContext<DeletedKey>, PollResponse<DeletedKey>> deletePol
.getValue()
.toObject(DeletedKeyBundle.class)));
} catch (HttpResponseException e) {
if (e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
if (e.getResponse() != null && e.getResponse().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
return new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue());
} else {
Expand Down Expand Up @@ -1285,7 +1285,7 @@ private Function<PollingContext<KeyVaultKey>, PollResponse<KeyVaultKey>> recover
return new PollResponse<>(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, createKeyVaultKey(
implClient.getKeyWithResponse(keyName, null, EMPTY_OPTIONS).getValue().toObject(KeyBundle.class)));
} catch (HttpResponseException e) {
if (e.getResponse().getStatusCode() == 404) {
if (e.getResponse() != null && e.getResponse().getStatusCode() == 404) {
return new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public String getKeyCollection() {
public Mono<Response<KeyVaultKey>> getKeyAsync() {
return keyClient.getKeyWithResponseAsync(keyName, keyVersion, EMPTY_OPTIONS)
.onErrorMap(HttpResponseException.class,
e -> e.getResponse().getStatusCode() == 403
e -> e.getResponse() != null && e.getResponse().getStatusCode() == 403
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e)
.map(response -> new SimpleResponse<>(response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ public static void verifyKeyPermissions(JsonWebKey jsonWebKey, KeyOperation keyO

public static boolean isThrowableRetryable(Throwable e) {
if (e instanceof HttpResponseException) {
int statusCode = ((HttpResponseException) e).getResponse().getStatusCode();
HttpResponseException httpResponseException = (HttpResponseException) e;

if (httpResponseException.getResponse() == null) {
return false;
}

int statusCode = httpResponseException.getResponse().getStatusCode();

// Not a retriable error code.
return statusCode != 501
Expand Down
2 changes: 2 additions & 0 deletions sdk/keyvault/azure-security-keyvault-secrets/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Fixed an issue where certain `HttpResponseException.getResponse()` calls could cause a `NullPointerException`. ([#47801](https://github.com/Azure/azure-sdk-for-java/issues/47801))

### Other Changes

## 4.10.4 (2025-10-27)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public Mono<Response<KeyVaultSecret>> setSecretWithResponse(KeyVaultSecret secre
// For some reason, the service does not return a 409 when a secret with the same name exists. Instead, it returns
// a 400.
static HttpResponseException mapSetSecretException(HttpResponseException e) {
return (e.getResponse().getStatusCode() == 400)
return (e.getResponse() != null && e.getResponse().getStatusCode() == 400)
Comment thread
vcolin7 marked this conversation as resolved.
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
Comment thread
vcolin7 marked this conversation as resolved.
: e;
}
Expand Down Expand Up @@ -443,7 +443,7 @@ public Mono<Response<KeyVaultSecret>> getSecretWithResponse(String name, String
// For some reason, the service does not return a 409 when a secret with the same name exists. Instead, it returns
// a 403.
static HttpResponseException mapGetSecretException(HttpResponseException e) {
if (e.getResponse().getStatusCode() == 403) {
if (e.getResponse() != null && e.getResponse().getStatusCode() == 403) {
return new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue());
} else {
return e;
Expand Down Expand Up @@ -597,7 +597,7 @@ private Function<PollingContext<DeletedSecret>, Mono<DeletedSecret>> deleteActiv
.map(response -> new PollResponse<>(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED,
createDeletedSecret(response.getValue().toObject(DeletedSecretBundle.class))))
.onErrorResume(HttpResponseException.class, exception -> {
if (exception.getResponse().getStatusCode() == 404) {
if (exception.getResponse() != null && exception.getResponse().getStatusCode() == 404) {
return Mono.just(new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue()));
} else {
Expand Down Expand Up @@ -790,7 +790,7 @@ private Function<PollingContext<KeyVaultSecret>, Mono<KeyVaultSecret>> recoverAc
.map(response -> new PollResponse<>(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED,
createKeyVaultSecret(response.getValue().toObject(SecretBundle.class))))
.onErrorResume(HttpResponseException.class, exception -> {
if (exception.getResponse().getStatusCode() == 404) {
if (exception.getResponse() != null && exception.getResponse().getStatusCode() == 404) {
return Mono.just(new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue()));
} else {
Expand Down Expand Up @@ -944,7 +944,7 @@ public Mono<Response<KeyVaultSecret>> restoreSecretBackupWithResponse(byte[] bac

// For some reason, the service does not return a 409 but a 400 in this case.
static HttpResponseException mapRestoreSecretException(HttpResponseException e) {
return (e.getResponse().getStatusCode() == 400)
return (e.getResponse() != null && e.getResponse().getStatusCode() == 400)
? new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue())
: e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ private Function<PollingContext<DeletedSecret>, PollResponse<DeletedSecret>> del
.getValue()
.toObject(DeletedSecretBundle.class)));
} catch (HttpResponseException e) {
if (e.getResponse().getStatusCode() == 404) {
if (e.getResponse() != null && e.getResponse().getStatusCode() == 404) {
return new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue());
} else {
Expand Down Expand Up @@ -720,7 +720,7 @@ private Function<PollingContext<KeyVaultSecret>, PollResponse<KeyVaultSecret>> r
return new PollResponse<>(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, createKeyVaultSecret(
implClient.getSecretWithResponse(name, "", EMPTY_OPTIONS).getValue().toObject(SecretBundle.class)));
} catch (HttpResponseException e) {
if (e.getResponse().getStatusCode() == 404) {
if (e.getResponse() != null && e.getResponse().getStatusCode() == 404) {
return new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
pollingContext.getLatestResponse().getValue());
} else {
Expand Down