From c1ccf2d77e1debf5e90cd184b079ff753dda9479 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 6 May 2011 05:56:58 +0200 Subject: [PATCH] =?utf8?q?Synchronize=20access=20on=20an=20identity?= =?utf8?q?=E2=80=99s=20trust=20cache.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This should fix #194. --- .../java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java index 3c04823..46f81d6 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java @@ -64,6 +64,7 @@ public class DefaultIdentity implements Identity { private final Map properties = Collections.synchronizedMap(new HashMap()); /** Cached trust. */ + /* synchronize on itself. */ private final WritableCache trustCache = new MemoryCache(new ValueRetriever() { @Override @@ -249,7 +250,9 @@ public class DefaultIdentity implements Identity { @Override public Trust getTrust(OwnIdentity ownIdentity) { try { - return trustCache.get(ownIdentity); + synchronized (trustCache) { + return trustCache.get(ownIdentity); + } } catch (CacheException ce1) { logger.log(Level.WARNING, "Could not get trust for OwnIdentity: " + ownIdentity, ce1); return null; @@ -265,7 +268,9 @@ public class DefaultIdentity implements Identity { * The trust received for this identity */ void setTrustPrivate(OwnIdentity ownIdentity, Trust trust) { - trustCache.put(ownIdentity, trust); + synchronized (trustCache) { + trustCache.put(ownIdentity, trust); + } } // -- 2.7.4