Skip to content
This repository was archived by the owner on Nov 7, 2020. It is now read-only.

Commit f3cd870

Browse files
committedAug 26, 2013
[JENKINS-18775] It is necessary to synchronize access to converters, not just typeToConverterMap.
1 parent f669b43 commit f3cd870

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed
 

‎xstream/src/java/com/thoughtworks/xstream/core/DefaultConverterLookup.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import com.thoughtworks.xstream.core.util.PrioritizedList;
1919
import com.thoughtworks.xstream.mapper.Mapper;
2020

21-
import java.util.Collections;
22-
import java.util.HashMap;
2321
import java.util.Iterator;
2422
import java.util.Map;
2523
import java.util.WeakHashMap;
@@ -34,7 +32,7 @@
3432
public class DefaultConverterLookup implements ConverterLookup, ConverterRegistry, Caching {
3533

3634
private final PrioritizedList converters = new PrioritizedList();
37-
private transient Map typeToConverterMap = Collections.synchronizedMap(new WeakHashMap());
35+
private transient Map typeToConverterMap;
3836

3937
public DefaultConverterLookup() {
4038
}
@@ -45,7 +43,10 @@ public DefaultConverterLookup() {
4543
public DefaultConverterLookup(Mapper mapper) {
4644
}
4745

48-
public Converter lookupConverterForType(Class type) {
46+
public synchronized Converter lookupConverterForType(Class type) {
47+
if (typeToConverterMap == null) {
48+
typeToConverterMap = new WeakHashMap();
49+
}
4950
Converter cachedConverter = (Converter) typeToConverterMap.get(type);
5051
if (cachedConverter != null) {
5152
return cachedConverter;
@@ -61,7 +62,10 @@ public Converter lookupConverterForType(Class type) {
6162
throw new ConversionException("No converter specified for " + type);
6263
}
6364

64-
public void registerConverter(Converter converter, int priority) {
65+
public synchronized void registerConverter(Converter converter, int priority) {
66+
if (typeToConverterMap == null) {
67+
typeToConverterMap = new WeakHashMap();
68+
}
6569
converters.add(converter, priority);
6670
for (Iterator iter = typeToConverterMap.keySet().iterator(); iter.hasNext();) {
6771
Class type = (Class) iter.next();
@@ -71,7 +75,10 @@ public void registerConverter(Converter converter, int priority) {
7175
}
7276
}
7377

74-
public void flushCache() {
78+
public synchronized void flushCache() {
79+
if (typeToConverterMap == null) {
80+
typeToConverterMap = new WeakHashMap();
81+
}
7582
typeToConverterMap.clear();
7683
Iterator iterator = converters.iterator();
7784
while (iterator.hasNext()) {
@@ -82,8 +89,4 @@ public void flushCache() {
8289
}
8390
}
8491

85-
private Object readResolve() {
86-
typeToConverterMap = Collections.synchronizedMap(new HashMap());
87-
return this;
88-
}
8992
}

0 commit comments

Comments
 (0)
This repository has been archived.