[ 
https://issues.apache.org/jira/browse/MYFACES-2840?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12892273#action_12892273
 ] 

Jakob Korherr commented on MYFACES-2840:
----------------------------------------

Hi Bernd,

I ran into this problem while refactoring the current FlashImpl. This impl uses 
the SubKeyMap. Take a look at its implementation of Entries.clear() and also 
the implementation of clear() from AbstractMap:

public void clear() {
        entrySet().clear();
}

       @Override
        public void clear()
        {
            Iterator<String> keys = _base.keySet().iterator();
            while (keys.hasNext())
            {
                String key = keys.next();
                if (key != null && key.startsWith(_prefix))
                {
                    keys.remove();
                }
            }
        }

There we have the call to keys.remove() and keys beeing the Iterator of the 
AbstractAttributeMap's keySet (in this case it's a SessionMap).

However the change is just an improvement, because you won't get a 
ConcurrentModificationException anymore, but the keySet iterator behaves 
exactly the same in any other scenario.

Regards,
Jakob


> Use a copied Iterator instead of the real Enumeration in 
> AbstractAttributeMap.AbstractAttributeIterator
> -------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-2840
>                 URL: https://issues.apache.org/jira/browse/MYFACES-2840
>             Project: MyFaces Core
>          Issue Type: Task
>    Affects Versions: 1.1.8, 1.2.9, 2.0.1
>            Reporter: Jakob Korherr
>            Assignee: Jakob Korherr
>             Fix For: 1.1.9-SNAPSHOT, 1.2.10-SNAPSHOT, 2.0.2-SNAPSHOT
>
>
> We can use a copied version of the Enumeration from getAttributeNames() here, 
> because directly using it might cause a ConcurrentModificationException  when 
> performing remove(). Note that we can do this since the Enumeration from 
> getAttributeNames() will contain exactly the attribute names from the time 
> getAttributeNames() was called and it will not be updated if attributes are 
> removed or added.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to