Skip to content

Commit

Permalink
Merge branch '2.11' into 2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 12, 2020
2 parents c0a8928 + 25c4274 commit b6dbe87
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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 @@ -526,7 +526,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 @@ -573,7 +573,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
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ public void testCopy() throws Exception
assertFalse(m2.isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE));

// // Also, underlying JsonFactory instances should be distinct

assertNotSame(m.getFactory(), m2.getFactory());

// [databind#2755]: also need to copy this:
assertNotSame(m.getSubtypeResolver(), m2.getSubtypeResolver());

// [databind#122]: Need to ensure mix-ins are not shared
assertEquals(0, m.getSerializationConfig().mixInCount());
assertEquals(0, m2.getSerializationConfig().mixInCount());
Expand Down

0 comments on commit b6dbe87

Please sign in to comment.