Skip to content

Fix GraalVM native image compatibility for AzureIdentityEnvVars#47940

Merged
g2vinay merged 1 commit intoAzure:mainfrom
g2vinay:fix-identity-env-var-config
Feb 10, 2026
Merged

Fix GraalVM native image compatibility for AzureIdentityEnvVars#47940
g2vinay merged 1 commit intoAzure:mainfrom
g2vinay:fix-identity-env-var-config

Conversation

@g2vinay
Copy link
Member

@g2vinay g2vinay commented Feb 9, 2026

Resolves #47106

Replace reflection-dependent AzureIdentityEnvVars enum usage with direct string literal to avoid NullPointerException in GraalVM native images.

The ExpandableStringEnum base class uses reflection for static field initialization, which doesn't work in native images without explicit configuration. Using the string literal 'AZURE_TOKEN_CREDENTIALS' directly eliminates the reflection dependency while maintaining identical runtime behavior.

Fixes NullPointerException in IdentityClientOptions.loadFromConfiguration when running in GraalVM native builds (e.g., Quarkus applications).

@g2vinay g2vinay force-pushed the fix-identity-env-var-config branch from ed780cf to 84b313f Compare February 10, 2026 00:27
@g2vinay g2vinay marked this pull request as ready for review February 10, 2026 00:29
@g2vinay g2vinay requested a review from joshfree as a code owner February 10, 2026 00:29
Copilot AI review requested due to automatic review settings February 10, 2026 00:29
@g2vinay g2vinay requested review from a team as code owners February 10, 2026 00:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a GraalVM native-image compatibility issue in azure-identity by removing a reflection-dependent reference to AzureIdentityEnvVars when reading the AZURE_TOKEN_CREDENTIALS configuration value, preventing a NullPointerException in native builds.

Changes:

  • Removed AzureIdentityEnvVars usage from IdentityClientOptions.loadFromConfiguration and replaced it with the "AZURE_TOKEN_CREDENTIALS" string key.
  • Added a changelog entry documenting the GraalVM native-image NullPointerException fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClientOptions.java Avoids referencing AzureIdentityEnvVars during configuration loading to prevent GraalVM native-image reflection/static-init issues.
sdk/identity/azure-identity/CHANGELOG.md Documents the GraalVM native-image NullPointerException fix in the unreleased section.

Replace reflection-dependent AzureIdentityEnvVars enum usage with direct
string literal to avoid NullPointerException in GraalVM native images.

The ExpandableStringEnum base class uses reflection for static field
initialization, which doesn't work in native images without explicit
configuration. Using the string literal 'AZURE_TOKEN_CREDENTIALS' directly
eliminates the reflection dependency while maintaining identical runtime
behavior.

Fixes NullPointerException in IdentityClientOptions.loadFromConfiguration
when running in GraalVM native builds (e.g., Quarkus applications).
@g2vinay g2vinay force-pushed the fix-identity-env-var-config branch from 84b313f to 36c8024 Compare February 10, 2026 00:51
@anannya03
Copy link
Member

anannya03 commented Feb 10, 2026

I've a basic question- As per my understanding, when we reference the static fields in AzureIdentityEnvVars, it calls the fromString() method which inherently uses reflection. In a Native build like GraalVM, metadata isn't stored by default, so the reflections lookup fails and returns a null.

If a user running a native image tries to execute DAC->
DefaultAzureCredential cred = new DefaultAzureCredentialBuilder.requireEnvVar(AzureIdentityEnvVars.AZURE_TENANT_ID).build();,
wouldn't they encounter the same issue with static field being null?

@github-project-automation github-project-automation bot moved this from Untriaged to In Progress in Azure Identity SDK Improvements Feb 10, 2026
@g2vinay g2vinay merged commit d09af47 into Azure:main Feb 10, 2026
19 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Azure Identity SDK Improvements Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

[BUG] [azure-identity] com.azure.identity.AzureIdentityEnvVars missing in reflect-config.json

2 participants