From 704680d68da67eb5019ec0add92c220c9e44041c Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Tue, 24 Jan 2017 01:54:37 +0530 Subject: [PATCH] Fixing null pointer when roles are not specified on creating new user --- .../mgt/jaxrs/service/impl/UserManagementServiceImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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);