diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 59b3a393f3..7181fc5a5d 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -1003,6 +1003,10 @@ Mark Schäfer (mark--@github) * Reported #2520: Sub-optimal exception message when failing to deserialize non-static inner classes (2.10.1) +Fabian Lange (CodingFabian@github) + * Reported #2556: Contention in `TypeNameIdResolver.idFromClass()` + (2.10.2) + Ville Koskela (vjkoskela@github) * Contributed #2487: BeanDeserializerBuilder Protected Factory Method for Extension (2.11.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 7a23dd36b8..922082255b 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -31,6 +31,8 @@ Project: jackson-databind (reported by Jon A) #2553: JsonDeserialize(contentAs=...) broken with raw collections (reported by cpopp@github) +#2556: Contention in `TypeNameIdResolver.idFromClass()` + (reported by Fabian L) 2.10.1 (09-Nov-2019) diff --git a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeNameIdResolver.java b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeNameIdResolver.java index b832a14d12..36dbf6f02e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeNameIdResolver.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeNameIdResolver.java @@ -91,6 +91,10 @@ protected String idFromClass(DatabindContext ctxt, Class cls) // `JavaType` being resolved, not underlying class. Hence commented out in // 3.x. There should be better way to support whatever the use case is. + // 29-Nov-2019, tatu: Looking at 2.x, test in `TestTypeModifierNameResolution` suggested + // that use of `TypeModifier` was used for demoting some types (from impl class to + // interface. For what that's worth. Still not supported for 3.x until proven necessary + // cls = _typeFactory.constructType(cls).getRawClass(); final String key = cls.getName(); @@ -98,17 +102,20 @@ protected String idFromClass(DatabindContext ctxt, Class cls) synchronized (_typeToId) { name = _typeToId.get(key); + } + + if (name == null) { + // 24-Feb-2011, tatu: As per [JACKSON-498], may need to dynamically look up name + // can either throw an exception, or use default name... + if (ctxt.isAnnotationProcessingEnabled()) { + name = ctxt.getAnnotationIntrospector().findTypeName(ctxt.getConfig(), + ctxt.introspectClassAnnotations(cls)); + } if (name == null) { - // 24-Feb-2011, tatu: As per [JACKSON-498], may need to dynamically look up name - // can either throw an exception, or use default name... - if (ctxt.isAnnotationProcessingEnabled()) { - name = ctxt.getAnnotationIntrospector().findTypeName(ctxt.getConfig(), - ctxt.introspectClassAnnotations(cls)); - } - if (name == null) { - // And if still not found, let's choose default? - name = _defaultTypeId(cls); - } + // And if still not found, let's choose default? + name = _defaultTypeId(cls); + } + synchronized (_typeToId) { _typeToId.put(key, name); } }