From 567e38a811ea643ad56837dd79e9a385f0d5a650 Mon Sep 17 00:00:00 2001 From: dhaura Date: Tue, 10 Dec 2024 11:08:52 +0530 Subject: [PATCH] Handle NPE in checking template existence. --- .../mgt/store/UnifiedTemplateManager.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/UnifiedTemplateManager.java b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/UnifiedTemplateManager.java index f91d3a39..ecb6d042 100644 --- a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/UnifiedTemplateManager.java +++ b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/store/UnifiedTemplateManager.java @@ -65,11 +65,8 @@ public void addNotificationTemplateType(String displayName, String notificationC public boolean isNotificationTemplateTypeExists(String displayName, String notificationChannel, String tenantDomain) throws NotificationTemplateManagerServerException { - boolean templateTypeExists = - systemDefaultTemplateManager.isNotificationTemplateTypeExists(displayName, notificationChannel, - tenantDomain); - - if (templateTypeExists) { + if (systemDefaultTemplateManager.isNotificationTemplateTypeExists(displayName, notificationChannel, + tenantDomain)) { return true; } @@ -79,12 +76,16 @@ public boolean isNotificationTemplateTypeExists(String displayName, String notif OrgResourceResolverService orgResourceResolverService = I18nMgtDataHolder.getInstance().getOrgResourceResolverService(); - return orgResourceResolverService.getResourcesFromOrgHierarchy( + Boolean templateTypeExists = orgResourceResolverService.getResourcesFromOrgHierarchy( organizationId, LambdaExceptionUtils.rethrowFunction( orgId -> notificationTemplateTypeExistenceRetriever(displayName, notificationChannel, orgId)), new FirstFoundAggregationStrategy<>()); + if (templateTypeExists != null) { + return templateTypeExists; + } + return false; } catch (OrganizationManagementException | OrgResourceHierarchyTraverseException e) { String errorMsg = String.format("Unexpected server error occurred while checking the existence of " + "email template type: %s for tenant: %s", displayName, tenantDomain); @@ -173,11 +174,8 @@ public boolean isNotificationTemplateExists(String displayName, String locale, S String applicationUuid, String tenantDomain) throws NotificationTemplateManagerServerException { - boolean templateExists = - systemDefaultTemplateManager.isNotificationTemplateExists(displayName, locale, notificationChannel, - null, tenantDomain); - - if (templateExists) { + if (systemDefaultTemplateManager.isNotificationTemplateExists(displayName, locale, notificationChannel, + null, tenantDomain)) { return true; } @@ -187,12 +185,16 @@ public boolean isNotificationTemplateExists(String displayName, String locale, S OrgResourceResolverService orgResourceResolverService = I18nMgtDataHolder.getInstance().getOrgResourceResolverService(); - return orgResourceResolverService.getResourcesFromOrgHierarchy( + Boolean templateExists = orgResourceResolverService.getResourcesFromOrgHierarchy( organizationId, LambdaExceptionUtils.rethrowFunction( orgId -> notificationTemplateExistenceRetriever(displayName, locale, notificationChannel, applicationUuid, orgId)), new FirstFoundAggregationStrategy<>()); + if (templateExists != null) { + return templateExists; + } + return false; } catch (OrganizationManagementException | OrgResourceHierarchyTraverseException e) { String errorMsg = String.format("Unexpected server error occurred while checking the existence of " + "email template with type: %s for tenant: %s", displayName, tenantDomain);