You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jo...@apache.org on 2007/10/18 18:16:20 UTC
svn commit: r586024 -
/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java
Author: jonl
Date: Thu Oct 18 09:16:19 2007
New Revision: 586024
URL: http://svn.apache.org/viewvc?rev=586024&view=rev
Log:
HashMap data structure was being corrupted by highly concurrent access, causing infinite loops on servers. Switched to a ConcurrentHashMap which has been rigged to store null values as a special constant String reference.
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java?rev=586024&r1=586023&r2=586024&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java Thu Oct 18 09:16:19 2007
@@ -25,6 +25,7 @@
import org.apache.wicket.model.IModel;
import org.apache.wicket.resource.loader.IStringResourceLoader;
import org.apache.wicket.settings.IResourceSettings;
+import org.apache.wicket.util.concurrent.ConcurrentHashMap;
import org.apache.wicket.util.string.AppendingStringBuffer;
import org.apache.wicket.util.string.interpolator.PropertyVariableInterpolator;
import org.slf4j.Logger;
@@ -51,9 +52,11 @@
{
private static final Logger logger = LoggerFactory.getLogger(Localizer.class);
-
/** Cache properties */
- private Map cache = new HashMap();
+ private Map cache = new ConcurrentHashMap();
+
+ /** ConcurrentHashMap does not allow null values */
+ private static final String NULL_VALUE = "<null-value>";
/**
* Create the utils instance class backed by the configuration information contained within the
@@ -247,8 +250,8 @@
if (resourceSettings.getThrowExceptionOnMissingResource())
{
- AppendingStringBuffer message = new AppendingStringBuffer("Unable to find resource: " +
- key);
+ AppendingStringBuffer message = new AppendingStringBuffer("Unable to find resource: "
+ + key);
if (component != null)
{
message.append(" for component: ");
@@ -270,7 +273,15 @@
*/
protected void putIntoCache(final String cacheKey, final String string)
{
- cache.put(cacheKey, string);
+ // ConcurrentHashMap does not allow null values
+ if (string == null)
+ {
+ cache.put(cacheKey, NULL_VALUE);
+ }
+ else
+ {
+ cache.put(cacheKey, string);
+ }
}
/**
@@ -281,7 +292,17 @@
*/
protected String getFromCache(final String cacheKey)
{
- return (String)cache.get(cacheKey);
+ final String value = (String)cache.get(cacheKey);
+
+ // ConcurrentHashMap does not allow null values
+ if (value == NULL_VALUE)
+ {
+ return null;
+ }
+ else
+ {
+ return value;
+ }
}
/**