From 128b5f64aab640148ece030cbb438883ab280b86 Mon Sep 17 00:00:00 2001 From: charitha Date: Mon, 22 Oct 2018 10:36:58 +0530 Subject: [PATCH] Fixed NPE in sending push notifications --- .../task/PushNotificationSchedulerTask.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java index 133ba08cb0..4f79999c8e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/task/PushNotificationSchedulerTask.java @@ -86,11 +86,18 @@ public class PushNotificationSchedulerTask implements Runnable { NotificationStrategy notificationStrategy = provider.getNotificationStrategyByDeviceType (operationMapping.getDeviceIdentifier().getType()); // Send the push notification on given strategy - notificationStrategy.execute(new NotificationContext(operationMapping.getDeviceIdentifier(), - provider.getOperation(operationMapping.getDeviceIdentifier().getType(), operationMapping - .getOperationId()))); - operationMapping.setPushNotificationStatus(Operation.PushNotificationStatus.COMPLETED); - operationsCompletedList.add(operationMapping); + if (notificationStrategy != null) { + notificationStrategy.execute(new NotificationContext(operationMapping.getDeviceIdentifier(), + provider.getOperation(operationMapping.getDeviceIdentifier().getType(), operationMapping + .getOperationId()))); + operationMapping.setPushNotificationStatus(Operation.PushNotificationStatus.COMPLETED); + operationsCompletedList.add(operationMapping); + } else { + if (log.isDebugEnabled()) { + log.debug("Tenant '" + PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getTenantDomain() + "' does not have push notification strategy."); + } + } } catch (DeviceManagementException e) { log.error("Error occurred while getting notification strategy for operation mapping " + operationMapping.getDeviceIdentifier().getType(), e); @@ -121,7 +128,7 @@ public class PushNotificationSchedulerTask implements Runnable { log.debug("Push notification job running completed."); } } catch (Throwable cause) { - log.error("PushNotificationSchedulerTask failed due to " + cause); + log.error("PushNotificationSchedulerTask failed due to " + cause.getMessage(), cause); } } }