Azure / Azure/azure-sdk-for-java
[BUG] mgmt eventhubs , NullPointerException in DisasterRecoveryPairingAuthorizationRuleImpl when listing Geo-DR authorization rules
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 2.2k
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 178
Description
**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**
```text
java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:233)
at com.azure.resourcemanager.eventhubs.implementation.Ancestors$TwoAncestor.(Ancestors.java:52)
at com.azure.resourcemanager.eventhubs.implementation.Ancestors$TwoAncestor.(Ancestors.java:58)
at com.azure.resourcemanager.eventhubs.implementation.DisasterRecoveryPairingAuthorizationRuleImpl.(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()`:
```java
PagedIterable 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:
```java
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:
```java
PagedIterable rules = pairing.listAuthorizationRules();
TestUtilities.getSize(rules); // NPE here
```
Contributor guide
Assessment
This issue has not been assessed yet.