Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 12, 2020
1 parent cc1dd92 commit 97ed5c9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Project: jackson-databind

#2486: Builder Deserialization with JsonCreator Value vs Array
(reported by Ville K)
#2755: `StdSubtypeResolver` is not thread safe (possibly due to copy
not being made with `ObjectMapper.copy()`)
(reported by tjwilson90@github)

2.11.0 (26-Apr-2020)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public boolean useForType(JavaType t)
* (should very quickly converge to zero after startup), let's
* explicitly define a low concurrency setting.
*<p>
* Since version 1.5, these may are either "raw" deserializers (when
* These may are either "raw" deserializers (when
* no type information is needed for base type), or type-wrapped
* deserializers (if it is needed)
*/
Expand Down Expand Up @@ -559,7 +559,7 @@ protected ObjectMapper(ObjectMapper src)
{
_jsonFactory = src._jsonFactory.copy();
_jsonFactory.setCodec(this);
_subtypeResolver = src._subtypeResolver;
_subtypeResolver = src._subtypeResolver.copy();
_typeFactory = src._typeFactory;
_injectableValues = src._injectableValues;
_configOverrides = src._configOverrides.copy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,25 @@
*/
public abstract class SubtypeResolver
{
/**
* Method called by {@code ObjectMapper.copy()} to make sure that
* {@link SubtypeResolver} instances used by two independent mappers
* can not cause thread-safety issues: if resolver is immutable, it
* may return {@code this}, but if not, it should create a copy with
* same configuration and return that instead.
*
* @return Either new instance with same configuration as this one (if
* instances are mutable), or this instance (if immutable)
*
* @since 2.12
*/
public SubtypeResolver copy() {
return this;
}

/*
/**********************************************************
/* Methods for registering external subtype definitions
/* Methods for registering external subtype definitions (init/config)
/**********************************************************
*/

Expand All @@ -36,7 +52,7 @@ public abstract class SubtypeResolver

/*
/**********************************************************
/* Subtype resolution
/* Subtype resolution (public API)
/**********************************************************
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ public class StdSubtypeResolver

public StdSubtypeResolver() { }

// @since 2.12
protected StdSubtypeResolver(StdSubtypeResolver src) {
LinkedHashSet<NamedType> reg = src._registeredSubtypes;
_registeredSubtypes = (reg == null) ? null
: new LinkedHashSet<>(reg);
}

// @since 2.12
@Override
public SubtypeResolver copy() {
return new StdSubtypeResolver(this);
}

/*
/**********************************************************
/* Subtype registration
Expand Down

0 comments on commit 97ed5c9

Please sign in to comment.