From: David ‘Bombe’ Roden Date: Fri, 6 May 2011 03:56:58 +0000 (+0200) Subject: Synchronize access on an identity’s trust cache. X-Git-Tag: 0.6.4^2~27 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=c1ccf2d77e1debf5e90cd184b079ff753dda9479 Synchronize access on an identity’s trust cache. This should fix #194. --- 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); + } } //