Skip to content

Commit

Permalink
Fixed ConcurrentModificationException in initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Jan 10, 2024
1 parent c39895f commit 11ac90f
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ public class JsonReader {
* @return The cached or created object mapper.
*/
private static ObjectMapper getObjectMapper(ModelRegistry modelRegistry, boolean isAdmin) {
ObjectMapper mapper;
if (isAdmin) {
mapper = mappersAdmin.get(modelRegistry);
} else {
mapper = mappers.get(modelRegistry);
}
if (mapper == null) {
// computeIfAbsent is not thread-safe, and we don't want this method to be synchronised.
mapper = initObjectMapper(modelRegistry, isAdmin);
}
return mapper;
}

private static synchronized ObjectMapper initObjectMapper(ModelRegistry modelRegistry, boolean isAdmin) {
if (isAdmin) {
return mappersAdmin.computeIfAbsent(modelRegistry, mr -> createObjectMapper(mr, isAdmin));
} else {
Expand All @@ -84,9 +98,7 @@ private static ObjectMapper getObjectMapper(ModelRegistry modelRegistry, boolean
* mapper for.
* @return The created object mapper.
*/
private static ObjectMapper createObjectMapper(ModelRegistry modelRegistry, boolean isAdmin) {
// ToDo: Allow extensions to add deserializers

private static synchronized ObjectMapper createObjectMapper(ModelRegistry modelRegistry, boolean isAdmin) {
GeoJsonDeserializier geoJsonDeserializier = new GeoJsonDeserializier();
for (String encodingType : GeoJsonDeserializier.ENCODINGS) {
CustomDeserializationManager.getInstance().registerDeserializer(encodingType, geoJsonDeserializier);
Expand Down

0 comments on commit 11ac90f

Please sign in to comment.