I am facing a bizarre problem. In the below code fragment, the 2nd for loop is breaking after one iteration, when I am calling userRoles.removeRole(strRole). There are 2 elements in the list. The first for loop is executing twice. But the 2nd one is executing only once. The said method call returns boolean. Could anyone please help me what's the wrong in my code?
if(userRoles != null)
{
List<String> roles = userRoles.getRoles();
String strUserName = userRoles.getUserName();
for(String strRole: roles)
{
System.out.println("role : " + strRole);
}
//for(String strRole: roles)
for(int count = 0; count < roles.size() ; count++)
{
String strRole = roles.get(count);
System.out.println("role before check: " + strRole);
if(ur.hasRoleForUser(strRole, strUserName))
{
System.out.println("role after check: " + strRole);
userRoles.removeRole(strRole);
}
}
System.out.println("role length: " + userRoles.getRoles().size());
if(userRoles.getRoles().size() > 0)
{
ur.addUserRoles(userRoles);
}
blnSuccess = true;
}