Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[JENKINS-18775] It is necessary to synchronize access to converters, …
…not just typeToConverterMap.
  • Loading branch information
jglick committed Aug 26, 2013
1 parent f669b43 commit f3cd8709b1bb640109ddd60daebe7d69bdb719e1
Showing with 13 additions and 10 deletions.
  1. +13 −10 xstream/src/java/com/thoughtworks/xstream/core/DefaultConverterLookup.java
@@ -18,8 +18,6 @@
import com.thoughtworks.xstream.core.util.PrioritizedList;
import com.thoughtworks.xstream.mapper.Mapper;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;
@@ -34,7 +32,7 @@
public class DefaultConverterLookup implements ConverterLookup, ConverterRegistry, Caching {

private final PrioritizedList converters = new PrioritizedList();
private transient Map typeToConverterMap = Collections.synchronizedMap(new WeakHashMap());
private transient Map typeToConverterMap;

public DefaultConverterLookup() {
}
@@ -45,7 +43,10 @@ public DefaultConverterLookup() {
public DefaultConverterLookup(Mapper mapper) {
}

public Converter lookupConverterForType(Class type) {
public synchronized Converter lookupConverterForType(Class type) {
if (typeToConverterMap == null) {
typeToConverterMap = new WeakHashMap();
}
Converter cachedConverter = (Converter) typeToConverterMap.get(type);
if (cachedConverter != null) {
return cachedConverter;
@@ -61,7 +62,10 @@ public Converter lookupConverterForType(Class type) {
throw new ConversionException("No converter specified for " + type);
}

public void registerConverter(Converter converter, int priority) {
public synchronized void registerConverter(Converter converter, int priority) {
if (typeToConverterMap == null) {
typeToConverterMap = new WeakHashMap();
}
converters.add(converter, priority);
for (Iterator iter = typeToConverterMap.keySet().iterator(); iter.hasNext();) {
Class type = (Class) iter.next();
@@ -71,7 +75,10 @@ public void registerConverter(Converter converter, int priority) {
}
}

public void flushCache() {
public synchronized void flushCache() {
if (typeToConverterMap == null) {
typeToConverterMap = new WeakHashMap();
}
typeToConverterMap.clear();
Iterator iterator = converters.iterator();
while (iterator.hasNext()) {
@@ -82,8 +89,4 @@ public void flushCache() {
}
}

private Object readResolve() {
typeToConverterMap = Collections.synchronizedMap(new HashMap());
return this;
}
}

0 comments on commit f3cd870

Please sign in to comment.