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);