From 964be98524046ae20431d0b93b3cc826414851c7 Mon Sep 17 00:00:00 2001 From: Warren Zhu Date: Mon, 4 Jun 2018 14:44:17 +0800 Subject: [PATCH] Implement workaround of Azure management api throw NPE when get unexisted namespace --- .../src/main/java/eventhub/integration/AzureAdmin.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-cloud-azure-eventhub/src/main/java/eventhub/integration/AzureAdmin.java b/spring-cloud-azure-eventhub/src/main/java/eventhub/integration/AzureAdmin.java index cee1875f..962ccd03 100644 --- a/spring-cloud-azure-eventhub/src/main/java/eventhub/integration/AzureAdmin.java +++ b/spring-cloud-azure-eventhub/src/main/java/eventhub/integration/AzureAdmin.java @@ -46,14 +46,14 @@ public class AzureAdmin { } public EventHubNamespace getOrCreateEventHubNamespace(String namespace) { - EventHubNamespace eventHubNamespace = azure.eventHubNamespaces().getByResourceGroup(resourceGroup, namespace); - - if (eventHubNamespace == null) { + try { + return azure.eventHubNamespaces().getByResourceGroup(resourceGroup, namespace); + } catch (NullPointerException e) { + // azure management api has no way to determine whether an eventhub namespace exists + // Workaround for this is by catching NPE return azure.eventHubNamespaces().define(namespace).withRegion(region) .withExistingResourceGroup(resourceGroup).create(); } - - return eventHubNamespace; } public StorageAccount getOrCreateStorageAccount(String name) {