diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java index 8b2dcdc841..bebeb3db2c 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java @@ -697,26 +697,29 @@ public class UserManagementServiceImpl implements UserManagementService { user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); userList.add(user); } - - int toIndex = offset + limit; - int listSize = userList.size(); - int lastIndex = listSize - 1; - - List offsetList; - if (offset <= lastIndex) { - if (toIndex <= listSize) { - offsetList = userList.subList(offset, toIndex); + if (offset==0) { + return Response.status(Response.Status.OK).entity(userList).build(); + } else { + int toIndex = offset + limit; + int listSize = userList.size(); + int lastIndex = listSize - 1; + + List offsetList; + if (offset <= lastIndex) { + if (toIndex <= listSize) { + offsetList = userList.subList(offset, toIndex); + } else { + offsetList = userList.subList(offset, listSize); + } } else { - offsetList = userList.subList(offset, listSize); + offsetList = new ArrayList<>(); } - } else { - offsetList = new ArrayList<>(); - } - UserInfoList result = new UserInfoList(); - result.setList(offsetList); - result.setCount(userList.size()); + UserInfoList result = new UserInfoList(); + result.setList(offsetList); + result.setCount(userList.size()); - return Response.status(Response.Status.OK).entity(result).build(); + return Response.status(Response.Status.OK).entity(result).build(); + } } catch (UserStoreException e) { String msg = "Error occurred while retrieving the list of users using the filter : " + filter; log.error(msg, e);