PortletStateHolder in the JBoss PortletBridge and ConcurrentModificationException

Today I run again into my old problem with the PortletStateHolder. While he is under fire he throws a lot of ConcurrentModificationExceptions.

Here is one of these Exceptions:

Caused by: java.util.ConcurrentModificationException
at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:373)
at java.util.LinkedHashMap$KeyIterator.next(LinkedHashMap.java:384)
at de.koelnerwasser.portlet.bridge.MyPortletStateHolder
         .removeSessionStates(MyPortletStateHolder.javaa:198)

Because I synchronized every write access to the class variable “states” eg.:

public void addWindowState(StateId stateId, PortletWindowState state) {
  // prevent concurrent access
  synchronized (states) {
    states.put(stateId, state);
  }
 }

I wonder about the exceptions.  So I investigated the read access to “states” in the “getWindowState()” method:

public PortletWindowState getWindowState(StateId stateId) {
 PortletWindowState state = null;
  if (null != stateId) {
   state = states.get(stateId);
  }
  return state;
 }

I found that states.get() calls a put on the org.apache.commons.collections.LRUMap. Here is the code:

public Object get(Object key)
{
  if(!containsKey(key))
  {
    return null;
  } else {
    Object value = remove(key);
    super.put(key, value);
    return value;
  }

The put() call causes the ConcurrentModificationException. The solution is to synchronize every call on the state LRUMap.

3 thoughts on “PortletStateHolder in the JBoss PortletBridge and ConcurrentModificationException

  1. Hello Alex, sorry that I didn’t wrote a JIRA entry, I just forgot my JBoss Account password and didn’t want to create a new account…
    Now the account is created and I will attach the requested information to the issue in a few minutes.

  2. My brother suggested I might like this website. He was entirely right.
    This post truly made my day. You can not imagine simply
    how much time I had spent for this info! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*