From d5976deed8b95b6515181e8ceafd0ac2825de52e Mon Sep 17 00:00:00 2001 From: Ruwan Liyanage Date: Fri, 15 Nov 2019 08:17:37 +0000 Subject: [PATCH] Fix HTTP Error 500 issue on the role edit page --- .../impl/RoleManagementServiceImpl.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) 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 a142b35610..eea84761a5 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;