RFR: 8304818: Prune HttpURLConnection cache when corresponding Authenticator is garbage collected [v2]

Michael McMahon michaelm at openjdk.org
Fri Mar 24 16:49:00 UTC 2023


On Fri, 24 Mar 2023 16:22:17 GMT, Daniel Jeliński <djelinski at openjdk.org> wrote:

>> 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
>
> also, not sure how much it applies to ConcurrentHashMap, but `remove` changes the iteration order of the `HashMap`, and `iterator.remove()` does not.

Right. It could throw CME, but odd that it doesn't in the test. I'd prefer to use an Iterator than change to a ConcurrentHashMap.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13159#discussion_r1147832499


More information about the net-dev mailing list