diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 33495907d1..2b5a2e8d45 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -104,8 +104,11 @@ public Response addUser(UserInfo userInfo) { userInfo.getEmailAddress()); // calling addUser method of carbon user api List tmpRoles = new ArrayList<>(); + String[] userInfoRoles = userInfo.getRoles(); tmpRoles.add(DEFAULT_DEVICE_USER); - tmpRoles.addAll(Arrays.asList(userInfo.getRoles())); + if (userInfoRoles != null) { + tmpRoles.addAll(Arrays.asList(userInfoRoles)); + } String[] roles = new String[tmpRoles.size()]; tmpRoles.toArray(roles);