From 9ce1c2002ad493cca192920eb37d075a95fde8d4 Mon Sep 17 00:00:00 2001 From: Dilshan Edirisuriya Date: Tue, 22 Sep 2015 14:09:59 +0530 Subject: [PATCH] Null check in DAO --- .../wso2/carbon/device/mgt/core/scep/SCEPManagerImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/scep/SCEPManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/scep/SCEPManagerImpl.java index 8a59b1789e4..bdabe8b9d8c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/scep/SCEPManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/scep/SCEPManagerImpl.java @@ -50,7 +50,13 @@ public class SCEPManagerImpl implements SCEPManager { try { DeviceManagementDAOFactory.openConnection(); HashMap deviceHashMap = deviceDAO.getDevice(deviceIdentifier); - Integer tenantId = (Integer) deviceHashMap.keySet().toArray()[0]; + Object[] keySet = deviceHashMap.keySet().toArray(); + + if(keySet == null || keySet.length == 0) { + throw new SCEPException("Lookup device not found for the device identifier"); + } + + Integer tenantId = (Integer) keySet[0]; tenantedDeviceWrapper.setDevice(deviceHashMap.get(tenantId)); tenantedDeviceWrapper.setTenantId(tenantId);