hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Smiley (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HTTPCLIENT-969) BasicCookieStore.getCookies() returns non-threadsafe collection
Date Wed, 21 Jul 2010 02:07:49 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-969?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12890532#action_12890532

David Smiley commented on HTTPCLIENT-969:

By the way, I was looking at this simple class a bit more and I think it could be made even
simpler.  The code shows that the cookies are treated like a Set, yet strangely it doesn't
use a Set internally.  Use a TreeSet wrapped in Collections.synchronizedSet() and then you
don't need to mark each method as synchronized.  Perhaps in a couple places you'll need to
synchronize on the set.  You still need the defensive copy for getCookies().  If you want
to avoid that defensive copy, you can use a ConcurrentSkipListSet instead of the synchronized

> BasicCookieStore.getCookies() returns non-threadsafe collection
> ---------------------------------------------------------------
>                 Key: HTTPCLIENT-969
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-969
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>            Reporter: David Smiley
>            Priority: Minor
>             Fix For: 4.0.2, 4.1 Alpha3
> BasicCookieStore.getCookies() is a simple method.  It's synchronized, and it returns
an unmodifiable wrapper around the underlying cookie list.  If the caller were to then iterate
over it as another thread were to manipulate the cookie list via BasicCookieStore, this would
create a thread un-safe situation because both threads aren't doing their reading/writing
with the same lock (the reader doesn't even have a lock).
> I suggest fixing this by using CopyOnWriteArrayList, or by making a defensive copy in
> This issue might apply to some of the other basic implementations of some of the interfaces
but I haven't checked.

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

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org

View raw message