Skip to content

[BUG] mgmt eventhubs , NullPointerException in DisasterRecoveryPairingAuthorizationRuleImpl when listing Geo-DR authorization rules #47525

@v-huizhu2

Description

@v-huizhu2

Describe the bug

Running com.azure.resourcemanager.eventhubs.EventHubTests#canManageGeoDisasterRecoveryPairing throws a NullPointerException. The stack trace shows the exception happens when creating DisasterRecoveryPairingAuthorizationRuleImpl, specifically inside Ancestors.TwoAncestor constructor, which suggests one of the ancestor parameters is null.

Exception stack trace

java.lang.NullPointerException
    at java.base/java.util.Objects.requireNonNull(Objects.java:233)
    at com.azure.resourcemanager.eventhubs.implementation.Ancestors$TwoAncestor.<init>(Ancestors.java:52)
    at com.azure.resourcemanager.eventhubs.implementation.Ancestors$TwoAncestor.<init>(Ancestors.java:58)
    at com.azure.resourcemanager.eventhubs.implementation.DisasterRecoveryPairingAuthorizationRuleImpl.<init>(DisasterRecoveryPairingAuthorizationRuleImpl.java:29)
    at com.azure.resourcemanager.eventhubs.implementation.DisasterRecoveryPairingAuthorizationRulesImpl.wrapModel(DisasterRecoveryPairingAuthorizationRulesImpl.java:83)
    at com.azure.resourcemanager.resources.fluentcore.utils.PagedConverter$IteratorImpl.next(PagedConverter.java:255)
    at com.azure.resourcemanager.test.utils.TestUtilities.getSize(TestUtilities.java:58)
    at com.azure.resourcemanager.eventhubs.EventHubTests.canManageGeoDisasterRecoveryPairing(EventHubTests.java:533)
    ...

Code location

Test class: com/azure/resourcemanager/eventhubs/EventHubTests.java
Failing test: canManageGeoDisasterRecoveryPairing

In the test, the failure happens when iterating pairing.listAuthorizationRules():

PagedIterable<DisasterRecoveryPairingAuthorizationRule> rules = pairing.listAuthorizationRules();
Assertions.assertTrue(TestUtilities.getSize(rules) > 0);
for (DisasterRecoveryPairingAuthorizationRule rule : rules) {
    DisasterRecoveryPairingAuthorizationKey keys = rule.getKeys();
    ...
}

The NPE is thrown during TestUtilities.getSize(rules) when the first item is materialized.

Suspected cause

DisasterRecoveryPairingAuthorizationRulesImpl.wrapModel constructs a DisasterRecoveryPairingAuthorizationRuleImpl using ancestor information extracted from the inner model or parent context. One of the values passed into Ancestors.TwoAncestor is null, causing Objects.requireNonNull(...) to throw NullPointerException.

Most likely:

  • resourceGroupName or namespaceName is not correctly derived from DisasterRecoveryPairingAuthorizationRuleInner or the pairing context, or
  • the parsing logic for inner.id()/parent ID does not match the actual Event Hubs Geo-DR authorization rule resource ID format.

Expected behavior

pairing.listAuthorizationRules() should not throw NullPointerException during wrapModel. It should return an iterable (possibly empty) or, if required data is missing, fail with a clearer, validated error instead of a null ancestor.

To Reproduce

  1. Create two Event Hubs namespaces (primary and secondary) and enable Geo-DR:

    EventHubNamespace primaryNamespace = eventHubsManager.namespaces()
        .define(primaryName)
        .withRegion(Region.US_SOUTH_CENTRAL)
        .withNewResourceGroup(rgName)
        .disableLocalAuth()
        .create();
    
    EventHubNamespace secondaryNamespace = eventHubsManager.namespaces()
        .define(secondaryName)
        .withRegion(Region.US_NORTH_CENTRAL)
        .withExistingResourceGroup(rgName)
        .disableLocalAuth()
        .create();
    
    EventHubDisasterRecoveryPairing pairing = eventHubsManager.eventHubDisasterRecoveryPairings()
        .define(geodrName)
        .withExistingPrimaryNamespace(primaryNamespace)
        .withExistingSecondaryNamespace(secondaryNamespace)
        .create();
  2. Poll until the pairing reaches ProvisioningStateDR.SUCCEEDED.

  3. Call:

    PagedIterable<DisasterRecoveryPairingAuthorizationRule> rules = pairing.listAuthorizationRules();
    TestUtilities.getSize(rules); // NPE here

Metadata

Metadata

Assignees

Labels

MgmtThis issue is related to a management-plane library.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions