Skip to content

Commit c1250b7

Browse files
committed
Fix #2556
1 parent 9c646c8 commit c1250b7

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

release-notes/CREDITS-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -1002,3 +1002,7 @@ Richard Wise (Woodz@github)
10021002
Mark Schäfer (mark--@github)
10031003
* Reported #2520: Sub-optimal exception message when failing to deserialize non-static inner classes
10041004
(2.10.1)
1005+
1006+
Fabian Lange (CodingFabian@github)
1007+
* Reported #2556: Contention in `TypeNameIdResolver.idFromClass()`
1008+
(2.10.2)

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Project: jackson-databind
1010
(reported by Jon A)
1111
#2553: JsonDeserialize(contentAs=...) broken with raw collections
1212
(reported by cpopp@github)
13+
#2556: Contention in `TypeNameIdResolver.idFromClass()`
14+
(reported by Fabian L)
1315

1416
2.10.1 (09-Nov-2019)
1517

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeNameIdResolver.java

+19-13
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,29 @@ protected String idFromClass(Class<?> clazz)
8888
if (clazz == null) {
8989
return null;
9090
}
91-
Class<?> cls = _typeFactory.constructType(clazz).getRawClass();
92-
final String key = cls.getName();
91+
// NOTE: although we may need to let `TypeModifier` change actual type to use
92+
// for id, we can use original type as key for more efficient lookup:
93+
final String key = clazz.getName();
9394
String name;
94-
9595
synchronized (_typeToId) {
9696
name = _typeToId.get(key);
97+
}
98+
99+
if (name == null) {
100+
// 29-Nov-2019, tatu: As per test in `TestTypeModifierNameResolution` somehow
101+
// we need to do this odd piece here which seems unnecessary but isn't.
102+
Class<?> cls = _typeFactory.constructType(clazz).getRawClass();
103+
// 24-Feb-2011, tatu: As per [JACKSON-498], may need to dynamically look up name
104+
// can either throw an exception, or use default name...
105+
if (_config.isAnnotationProcessingEnabled()) {
106+
BeanDescription beanDesc = _config.introspectClassAnnotations(cls);
107+
name = _config.getAnnotationIntrospector().findTypeName(beanDesc.getClassInfo());
108+
}
97109
if (name == null) {
98-
// 24-Feb-2011, tatu: As per [JACKSON-498], may need to dynamically look up name
99-
// can either throw an exception, or use default name...
100-
if (_config.isAnnotationProcessingEnabled()) {
101-
BeanDescription beanDesc = _config.introspectClassAnnotations(cls);
102-
name = _config.getAnnotationIntrospector().findTypeName(beanDesc.getClassInfo());
103-
}
104-
if (name == null) {
105-
// And if still not found, let's choose default?
106-
name = _defaultTypeId(cls);
107-
}
110+
// And if still not found, let's choose default?
111+
name = _defaultTypeId(cls);
112+
}
113+
synchronized (_typeToId) {
108114
_typeToId.put(key, name);
109115
}
110116
}

0 commit comments

Comments
 (0)