javax.jcr.InvalidItemStateException: In adding a user to a group
Hi,
I am doing some load tests and i see the below error quite frequently and not sure how i can resolve it. My Sample code is fairly written. I am also using synchronized method just to make sure that no other thread is modifying the group. I am trying to add members to group and i have checked the reference of the method and none of the classes are calling the addMemberToGroup method apart from the one that i am invoking.
Here is the method. I have to mandatory call the save method inside the body because if other threads will modify the definition of group and before the save of current thread then it will result in another issue with jcr.
public synchronized boolean addMemberToGroup(String groupName, String userName, ResourceResolver adminResolver) throws RepositoryException { boolean success=false; if(StringUtils.isNotEmpty(groupName) && StringUtils.isNotEmpty(userName)){ UserManager userManager = adminResolver.adaptTo(UserManager.class); Authorizable userAuthorizable = userManager.getAuthorizable(userName); Authorizable groupAuthorizable = userManager.getAuthorizable(groupName); if (userAuthorizable instanceof User && groupAuthorizable instanceof Group) { Group group = (Group) groupAuthorizable; if (!group.isMember(userAuthorizable)) { group.addMember(userAuthorizable); adminResolver.adaptTo(Session.class).save(); success=true; } } } return success; }I have attached the exception trace that i am getting. No workflow is running on the groups as well.
at org.apache.jackrabbit.core.ItemSaveOperation.perform(ItemSaveOperation.java:262)
at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)
at org.apache.jackrabbit.core.ItemImpl.perform(ItemImpl.java:91)
at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:329)
at org.apache.jackrabbit.core.security.user.UserManagerImpl.setProtectedProperty(UserManagerImpl.java:782)
at org.apache.jackrabbit.core.security.user.GroupImpl$PropertyBasedMembershipProvider.addMember(GroupImpl.java:420)
at org.apache.jackrabbit.core.security.user.GroupImpl.addMember(GroupImpl.java:172)
at aaa.UserGroupOpeartionImpl.addMemberToGroup(UserGroupOpeartionImpl.java:147)
Any help in solving this would be appreciated.
Thanks