use CHM to avoid ConcurrentModificationExceptions at runtime
fixes
@@ -8,6 +8,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import com.mongodb.lang.Nullable;
@@ -33,7 +34,7 @@ import static java.lang.Boolean.FALSE;
public final class Conversions {
private static final Logger LOG = LoggerFactory.getLogger(Conversions.class);
- private static final Map<Class<?>, Map<Class<?>, Function<?, ?>>> CONVERSIONS = new HashMap<>();
+ private static final Map<Class<?>, Map<Class<?>, Function<?, ?>>> CONVERSIONS = new ConcurrentHashMap<>();
static {
registerStringConversions();
@@ -108,7 +109,6 @@ public final class Conversions {
/**
* Register a conversion between two types. For example, to register the conversion of {@link Date} to a {@link Long}, this method
* could be invoked as follows:
- *
* <code>
* register(Date.class, Long.class, Date::getTime);
* </code>
@@ -144,7 +144,7 @@ public final class Conversions {
}
final Function function = CONVERSIONS
- .computeIfAbsent(fromType, (f) -> new HashMap<>())
+ .computeIfAbsent(fromType, (f) -> new ConcurrentHashMap<>())
.get(target);
if (function == null) {
if (target.equals(String.class)) {
@@ -171,7 +171,6 @@ public final class Conversions {
/**
* Register a conversion between two types. For example, to register the conversion of {@link Date} to a {@link Long}, this method
* could be invoked as follows:
- *
* <code>
* register(Date.class, Long.class, Date::getTime);
* </code>
