diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index a142b356103..eea84761a58 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -253,21 +253,35 @@ public class RoleManagementServiceImpl implements RoleManagementService { roleInfo.setPermissionList(rolePermissions); String[] permListAr = new String[permList.size()]; roleInfo.setPermissions(permList.toArray(permListAr)); - return Response.status(Response.Status.OK).entity(roleInfo).build(); - } catch (UserStoreException | UserAdminException e) { - String msg = "Error occurred while retrieving the user role '" + roleName + "'"; + } catch (UserAdminException e) { + String msg = "Error occurred due to Unable to retrieve user role'" + roleName + "'"; log.error(msg, e); - return Response.serverError().entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.serverError() + .entity(new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()) + .build(); + } catch (UserStoreException e) { + String msg = "Error occurred while retrieving the UserStoreManager of the user role '" + + roleName + "'"; + log.error(msg, e); + return Response.serverError() + .entity(new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()) + .build(); } } private List iteratePermissions(UIPermissionNode uiPermissionNode, List list) { + //To prevent NullPointer exceptions + if (uiPermissionNode == null) { + return list; + } for (UIPermissionNode permissionNode : uiPermissionNode.getNodeList()) { - list.add(permissionNode.getResourcePath()); - if (permissionNode.getNodeList() != null && permissionNode.getNodeList().length > 0) { - iteratePermissions(permissionNode, list); + if (permissionNode != null) { + list.add(permissionNode.getResourcePath()); + if (permissionNode.getNodeList() != null + && permissionNode.getNodeList().length > 0) { + iteratePermissions(permissionNode, list); + } } } return list;