diff --git a/sdk/cosmos/azure-cosmos/CHANGELOG.md b/sdk/cosmos/azure-cosmos/CHANGELOG.md index 8cbf52e3f916..67d535bf6570 100644 --- a/sdk/cosmos/azure-cosmos/CHANGELOG.md +++ b/sdk/cosmos/azure-cosmos/CHANGELOG.md @@ -12,6 +12,7 @@ * Fixed JVM `` deadlock when multiple threads concurrently trigger Cosmos SDK class loading for the first time. - See [PR 48689](https://github.com/Azure/azure-sdk-for-java/pull/48689) * Fixed an issue where `CustomItemSerializer` was incorrectly applied to internal SDK query pipeline structures (e.g., `OrderByRowResult`, `Document`), causing deserialization failures in ORDER BY, GROUP BY, aggregate, DISTINCT, and hybrid search queries. - See [PR 48811](https://github.com/Azure/azure-sdk-for-java/pull/48811) * Fixed an issue where `SqlParameter` ignored the configured `CustomItemSerializer`, always using the internal default serializer instead. - See [PR 48811](https://github.com/Azure/azure-sdk-for-java/pull/48811) +* Fixed `NullPointerException` during `ClientTelemetry` static initialization when IMDS access is disabled (`COSMOS_DISABLE_IMDS_ACCESS=true`), which made every `CosmosAsyncClient` build fail with `NoClassDefFoundError`. - See [PR 48887](https://github.com/Azure/azure-sdk-for-java/pull/48887) #### Other Changes diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/clienttelemetry/ClientTelemetry.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/clienttelemetry/ClientTelemetry.java index f5f4f5797689..f25602529c7c 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/clienttelemetry/ClientTelemetry.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/clienttelemetry/ClientTelemetry.java @@ -47,15 +47,18 @@ private static ImplementationBridgeHelpers.CosmosClientTelemetryConfigHelper.Cos private static final Logger logger = LoggerFactory.getLogger(ClientTelemetry.class); private static final String USER_AGENT = Utils.getUserAgent(); + // Sentinel for "not on Azure VM" or "IMDS unreachable". + // Must be declared before CACHED_METADATA so that fetchAzureVmMetadata() + // never reads a null value during class initialization (e.g. when IMDS + // access is disabled via COSMOS_DISABLE_IMDS_ACCESS). + private static final AzureVMMetadata METADATA_NOT_AVAILABLE = new AzureVMMetadata(); + // Cached IMDS metadata Mono. Reactor's cache() ensures: // - The fetch executes at most once // - All concurrent subscribers share the single result // - The HTTP client is created and disposed within the fetch private static final Mono CACHED_METADATA = fetchAzureVmMetadata().cache(); - // Sentinel for "not on Azure VM" or "IMDS unreachable" - private static final AzureVMMetadata METADATA_NOT_AVAILABLE = new AzureVMMetadata(); - // IMDS Constants private static final String IMDS_AZURE_VM_METADATA = "http://169.254.169.254:80/metadata/instance?api-version=2020-06-01"; private static final Duration IMDS_DEFAULT_NETWORK_REQUEST_TIMEOUT = Duration.ofSeconds(5);