Skip to content

Commit fbba035

Browse files
author
Greg Williams
committed
Since HashSet is not thread-safe, getting a Set from ConcurrentHashMap which is thread-safe.
1 parent 02711da commit fbba035

File tree

1 file changed

+3
-2
lines changed
  • okhttp3-persistent-cookiejar/src/main/java/com/franmontiel/persistentcookiejar/cache

1 file changed

+3
-2
lines changed

okhttp3-persistent-cookiejar/src/main/java/com/franmontiel/persistentcookiejar/cache/SetCookieCache.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
package com.franmontiel.persistentcookiejar.cache;
1818

1919
import java.util.Collection;
20-
import java.util.HashSet;
20+
import java.util.Collections;
2121
import java.util.Iterator;
2222
import java.util.Set;
23+
import java.util.concurrent.ConcurrentHashMap;
2324

2425
import okhttp3.Cookie;
2526

@@ -28,7 +29,7 @@ public class SetCookieCache implements CookieCache {
2829
private Set<IdentifiableCookie> cookies;
2930

3031
public SetCookieCache() {
31-
cookies = new HashSet<>();
32+
cookies = Collections.newSetFromMap(new ConcurrentHashMap<IdentifiableCookie, Boolean>());
3233
}
3334

3435
@Override

0 commit comments

Comments
 (0)