[ 
https://issues.apache.org/jira/browse/IO-191?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12666135#action_12666135
 ] 

Jukka Zitting commented on IO-191:
----------------------------------

Responding to Sebb's comment first.

{quote}
If one thread creates a new collection whilst another is iterating it, then in 
the absence of synchronisation there is no guarantee what state the other 
thread will next see for the collection.
{quote}

Not true. For example, consider the following pseudocode where two threads, A 
and B, concurrently access the same collection.

{code}
A: iterator = collection.iterator();
A: iterator.next();
B: collection = new Collection();
A: iterator.next();
{code}

A continues to see the contents of the original collection while iterating, 
which IMHO is the only reasonable and deterministic behaviour in such cases. If 
thread B use collection.clear(), thread A would likely fail with a 
ConcurrentModificationException.

However, my objection applies only to cases where the collection is immutable 
after initialization (otherwise the threads would in any case need to worry 
about synchronization). In AndFileFilter this is not the case, so there I think 
using Collection.clear() is actually a valid option. This context is not 
visible in the patch, so I'd rather consider such changes on a case-by-case 
basis instead of as a part of a bigger changeset generated by an analyzer tool.

> Possible improvements using static analysis.
> --------------------------------------------
>
>                 Key: IO-191
>                 URL: https://issues.apache.org/jira/browse/IO-191
>             Project: Commons IO
>          Issue Type: Improvement
>            Reporter: Peter Lawrey
>            Priority: Trivial
>         Attachments: commons-io-static-analysis.patch
>
>   Original Estimate: 3h
>  Remaining Estimate: 3h
>


-- 
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