RFR: 8304818: Prune HttpURLConnection cache when corresponding Authenticator is garbage collected
Daniel Fuchs
dfuchs at openjdk.org
Fri Mar 24 14:54:32 UTC 2023
On Fri, 24 Mar 2023 14:43:14 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:
>> src/java.base/share/classes/sun/net/www/protocol/http/AuthCacheImpl.java line 85:
>>
>>> 83: LinkedList<AuthCacheValue> list) -> {
>>> 84: if (key.endsWith(authkey)) {
>>> 85: hashtable.remove(key);
>>
>> won't this throw a `ConcurrentModificationException`?
>
> That's a good point. One solution would be to use a ConcurrentHashMap instead of a simple HashMap.
jshell> var map = Map.of(1,1,2,2,3,3,4,4)
map ==> {1=1, 2=2, 3=3, 4=4}
jshell> var map2 = new HashMap<Integer, Integer>();
map2 ==> {}
jshell> map2.putAll(map)
jshell> map2.forEach((k, v) -> map2.remove(k));
| Exception java.util.ConcurrentModificationException
| at HashMap.forEach (HashMap.java:1432)
| at (#4:1)
jshell> var map3 = new ConcurrentHashMap<Integer, Integer>();
map3 ==> {}
jshell> map3.putAll(map)
jshell> map3.forEach((k, v) -> map3.remove(k));
jshell> map3.isEmpty()
$10 ==> true
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13159#discussion_r1147690791
More information about the net-dev
mailing list