Skip to content

Commit b23eebb

Browse files
authored
Minor clean up in JDKKeyDeserializer.EnumKD post #3990 (#4038)
1 parent 9429dfc commit b23eebb

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

src/main/java/tools/jackson/databind/deser/jdk/JDKKeyDeserializer.java

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -360,18 +360,18 @@ final static class EnumKD extends JDKKeyDeserializer
360360
protected final AnnotatedMethod _factory;
361361

362362
/**
363-
* Lazily constructed alternative in case there is need to
364-
* use 'toString()' method as the source.
363+
* Alternative resolver to parse enums with {@code toString()} method as the source.
364+
* Works when {@link DeserializationFeature#READ_ENUMS_USING_TO_STRING} is enabled.
365365
*/
366366
protected final EnumResolver _byToStringResolver;
367367

368368
/**
369-
* Lazily constructed alternative in case there is need to
370-
* parse using enum index method as the source.
369+
* Alternative resolver to parse enums with {@link Enum#ordinal()} method as the source.
370+
* Works when {@link EnumFeature#READ_ENUM_KEYS_USING_INDEX} is enabled.
371371
*
372372
* @since 2.15
373373
*/
374-
protected volatile EnumResolver _byIndexResolver;
374+
protected final EnumResolver _byIndexResolver;
375375

376376
/**
377377
* Look up map with <b>key</b> as <code>Enum.name()</code> converted by
@@ -416,8 +416,9 @@ public Object _parse(String key, DeserializationContext ctxt)
416416
Enum<?> e = res.findEnum(key);
417417
// If enum is found, no need to try deser using index
418418
if (e == null && ctxt.isEnabled(EnumFeature.READ_ENUM_KEYS_USING_INDEX)) {
419-
res = _getIndexResolver(ctxt);
420-
e = res.findEnum(key);
419+
if (_byIndexResolver != null) {
420+
e = _byIndexResolver.findEnum(key);
421+
}
421422
}
422423
if (e == null) {
423424
if ((_enumDefaultValue != null)
@@ -443,29 +444,6 @@ protected EnumResolver _resolveCurrentResolver(DeserializationContext ctxt) {
443444
? _byToStringResolver
444445
: _byNameResolver;
445446
}
446-
447-
/**
448-
* Since 2.16, {@link #_byIndexResolver} it is passed via
449-
* {@link #EnumKD(EnumResolver, AnnotatedMethod, EnumResolver, EnumResolver, EnumResolver)}, so there is no need for lazy
450-
* initialization. But kept for backward-compatibility reasons.
451-
*
452-
* @deprecated Since 2.16
453-
*/
454-
@Deprecated
455-
private EnumResolver _getIndexResolver(DeserializationContext ctxt) {
456-
EnumResolver res = _byIndexResolver;
457-
if (res == null) {
458-
synchronized (this) {
459-
res = _byIndexResolver;
460-
if (res == null) {
461-
res = EnumResolver.constructUsingIndex(ctxt.getConfig(),
462-
_byNameResolver.getEnumClass());
463-
_byIndexResolver = res;
464-
}
465-
}
466-
}
467-
return res;
468-
}
469447
}
470448

471449
/**

0 commit comments

Comments
 (0)