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

Daniel Kulp commented on FELIX-4609:
------------------------------------

Actually, the ScannerWatcher could also be adding a file to the changed set 
during this iteration.   The nio based Watcher could be called at pretty much 
any time and then add the file to the changed set.   

In addition to the above, I'd recommend changing from a HashSet to a 
ConcurrentHashMap or CopyOnWriteArraySet or some other concurrent safe 
implementation.

> Possible ConcurrentModificationException in WatcherScanner
> ----------------------------------------------------------
>
>                 Key: FELIX-4609
>                 URL: https://issues.apache.org/jira/browse/FELIX-4609
>             Project: Felix
>          Issue Type: Bug
>          Components: File Install
>    Affects Versions: fileinstall-3.4.0
>            Reporter: Daniel Kulp
>
> In some cases at startup, I'm getting:
> {code}
> 12:02:06,941 | ERROR | OT/container/etc | ?                                   
> ? | 6 - org.apache.felix.fileinstall - 3.4.0 | In main loop, we have serious 
> trouble
> java.util.ConcurrentModificationException
>     at java.util.HashMap$HashIterator.nextEntry(HashMap.java:922)[:1.7.0_67]
>     at java.util.HashMap$KeyIterator.next(HashMap.java:956)[:1.7.0_67]
>     at 
> org.apache.felix.fileinstall.internal.WatcherScanner.scan(WatcherScanner.java:70)[6:org.apache.felix.fileinstall:3.4.0]
>     at 
> org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:305)[6:org.apache.felix.fileinstall:3.4.0]
> {code}
> The problem looks to stem from line 83 of WatcherScanner.   The "changed" 
> HashSet is being modified (remove call) within the for loop that is iterating 
> over it. 
> Most likely, a small change of:
> {code}
> Index: WatcherScanner.java
> ===================================================================
> --- WatcherScanner.java       (revision 1619096)
> +++ WatcherScanner.java       (working copy)
> @@ -78,10 +78,8 @@
>                  if ((newChecksum == lastChecksum || reportImmediately)) {
>                      if (newChecksum != storedChecksum) {
>                          storedChecksums.put(file, newChecksum);
> -                        files.add(file);
> -                    } else {
> -                        changed.remove(file);
>                      }
> +                    files.add(file);
>                      if (reportImmediately) {
>                          removed.remove(file);
>                      }
> {code}
> will fix it, but untested at this point.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to