Skip to content

[BUG] Azure KeyVault - SecretAsyncClient NPE hides real exception. #47647

Description

@nicomz

Describe the bug
There are some conditions such as invalid credentials where there response is null and the access to the status code becomes a NPE hiding the underlying condition (real exception).
Mind looking at this fragment of the SecretAsyncClient :

static HttpResponseException mapGetSecretException(HttpResponseException e) { if (e.getResponse().getStatusCode() == 403) { return new ResourceModifiedException(e.getMessage(), e.getResponse(), e.getValue()); } else { return e; } }

If e.getResponse() is null then this ends in a NPE hiding important information such as a real ClientAuthenticationException.

Exception or Stack Trace
Caused by: java.lang.NullPointerException: Cannot invoke "com.azure.core.http.HttpResponse.getStatusCode()" because the return value of "com.azure.core.exception.HttpResponseException.getResponse()" is null at com.azure.security.keyvault.secrets.SecretAsyncClient.mapGetSecretException(SecretAsyncClient.java:446) at com.azure.security.keyvault.secrets.SecretClient.callWithMappedException(SecretClient.java:1092) at com.azure.security.keyvault.secrets.SecretClient.getSecret(SecretClient.java:322)

To Reproduce
Just attempt to retrieve a secret with invalid credentials.

Code Snippet
Add the code snippet that causes the issue.

Expected behavior
Null check on the getResponse() before attempting to call the getStatusCode().

Screenshots
If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

  • OS: [e.g. iOS] MacOS

  • IDE: [e.g. IntelliJ] IntelliJ

  • Library/Libraries: [e.g. com.azure:azure-core:1.16.0 (groupId:artifactId:version)]
    <dependency> <groupId>com.azure</groupId> <artifactId>azure-sdk-bom</artifactId> <version>1.3.3</version> <type>pom</type> <scope>import</scope> </dependency>

  • Java version: [e.g. 8] 8

  • App Server/Environment: [e.g. Tomcat, WildFly, Azure Function, Apache Spark, Databricks, IDE plugin or anything special]

  • Frameworks: [e.g. Spring Boot, Micronaut, Quarkus, etc]

If you suspect a dependency version mismatch (e.g. you see NoClassDefFoundError, NoSuchMethodError or similar), please check out Troubleshoot dependency version conflict article first. If it doesn't provide solution for the problem, please provide:

  • verbose dependency tree (mvn dependency:tree -Dverbose)
  • exception message, full stack trace, and any available logs

Additional context
Add any other context about the problem here.

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Metadata

Metadata

Assignees

Labels

KeyVaultbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions