[ 
https://issues.apache.org/jira/browse/SLING-4903?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14640507#comment-14640507
 ] 

Chetan Mehrotra commented on SLING-4903:
----------------------------------------

 No instead of cloning just create a new list like {{ List<MapEntry> 
entriesCopy =new ArrayList<MapEntry>(entries);}} and replaced the entry in 
entryMap like below

{code}
    /**
     * Add an entry to the resolve map.
     */
    private boolean addEntry(final Map<String, List<MapEntry>> entryMap, final 
String key, final MapEntry entry) {
        if (entry==null){
            return false;
        }
        List<MapEntry> entries = entryMap.get(key);
        if (entries == null) {
            entries = new ArrayList<MapEntry>();
            entries.add(entry);
            // and finally sort list
            Collections.sort(entries);
            entryMap.put(key, entries);
        } else {
            List<MapEntry> entriesCopy =new ArrayList<MapEntry>(entries);
            entriesCopy.add(entry);
            // and finally sort list
            Collections.sort( entriesCopy);
            entryMap.put(key, entriesCopy);
        }
        return true;
    }
{code}

> ConcurrentModificationException in MapEntries
> ---------------------------------------------
>
>                 Key: SLING-4903
>                 URL: https://issues.apache.org/jira/browse/SLING-4903
>             Project: Sling
>          Issue Type: Bug
>          Components: ResourceResolver
>            Reporter: Antonio Sanso
>            Assignee: Antonio Sanso
>         Attachments: SLING-4883-patch.txt, SLING-4883-test-patch.txt
>
>
> {code}
> org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught 
> Throwable java.util.ConcurrentModificationException: null
>  at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:859)
>  at java.util.ArrayList$Itr.next(ArrayList.java:831)
>  at 
> org.apache.sling.resourceresolver.impl.mapping.MapEntries$MapEntryIterator.seek(MapEntries.jav
>  a:1499)
>  at 
> org.apache.sling.resourceresolver.impl.mapping.MapEntries$MapEntryIterator.next(MapEntries.jav
>  a:1450)
>  at 
> org.apache.sling.resourceresolver.impl.mapping.MapEntries$MapEntryIterator.next(MapEntries.jav
>  a:1411)
>  at 
> org.apache.sling.resourceresolver.impl.ResourceResolverImpl.resolveInternal(ResourceResolverIm
>  pl.java:251)
>  at 
> org.apache.sling.resourceresolver.impl.ResourceResolverImpl.resolve(ResourceResolverImpl.java:
>  192)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to