diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index a6e4b943a..4b09dc529 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -20,6 +20,9 @@ Contributors: Ilya Ryzhenkov (@orangy) * #580: Lazy load UNIT_TYPE +WrongWrong (@k163377) +* #627: Merge creator cache for Constructor and Method + # 2.14.0 Richard Kwasnicki (Richie94@github) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 33ab5c7cc..604d4de7c 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -22,6 +22,7 @@ Co-maintainers: (fix via [jackson-dataformat-xml#547]) #580: Lazy load UNIT_TYPE (contributed by Ilya R) +#627: Merge creator cache for Constructor and Method 2.14.2 (28-Jan-2023) 2.14.1 (21-Nov-2022) diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt index 432b8518e..81400e869 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.introspect.AnnotatedMethod import com.fasterxml.jackson.databind.introspect.AnnotatedWithParams import com.fasterxml.jackson.databind.util.LRUMap import java.lang.reflect.Constructor +import java.lang.reflect.Executable import java.lang.reflect.Method import kotlin.reflect.KClass import kotlin.reflect.KFunction @@ -36,8 +37,7 @@ internal class ReflectionCache(reflectionCacheSize: Int) { private val javaClassToKotlin = LRUMap, KClass>(reflectionCacheSize, reflectionCacheSize) private val javaConstructorToKotlin = LRUMap, KFunction>(reflectionCacheSize, reflectionCacheSize) private val javaMethodToKotlin = LRUMap>(reflectionCacheSize, reflectionCacheSize) - private val javaConstructorToValueCreator = LRUMap, ConstructorValueCreator<*>>(reflectionCacheSize, reflectionCacheSize) - private val javaMethodToValueCreator = LRUMap>(reflectionCacheSize, reflectionCacheSize) + private val javaExecutableToValueCreator = LRUMap>(reflectionCacheSize, reflectionCacheSize) private val javaConstructorIsCreatorAnnotated = LRUMap(reflectionCacheSize, reflectionCacheSize) private val javaMemberIsRequired = LRUMap(reflectionCacheSize, reflectionCacheSize) private val kotlinGeneratedMethod = LRUMap(reflectionCacheSize, reflectionCacheSize) @@ -63,22 +63,25 @@ internal class ReflectionCache(reflectionCacheSize: Int) { is AnnotatedConstructor -> { val constructor = _withArgsCreator.annotated as Constructor - javaConstructorToValueCreator.get(constructor) + javaExecutableToValueCreator.get(constructor) ?: kotlinFromJava(constructor)?.let { val value = ConstructorValueCreator(it) - javaConstructorToValueCreator.putIfAbsent(constructor, value) ?: value + javaExecutableToValueCreator.putIfAbsent(constructor, value) ?: value } } is AnnotatedMethod -> { - val method = _withArgsCreator.annotated as Method + val method = _withArgsCreator.annotated - javaMethodToValueCreator.get(method) + javaExecutableToValueCreator.get(method) ?: kotlinFromJava(method)?.let { val value = MethodValueCreator.of(it) - javaMethodToValueCreator.putIfAbsent(method, value) ?: value + javaExecutableToValueCreator.putIfAbsent(method, value) ?: value } } - else -> throw IllegalStateException("Expected a constructor or method to create a Kotlin object, instead found ${_withArgsCreator.annotated.javaClass.name}") + else -> throw IllegalStateException( + "Expected a constructor or method to create a Kotlin object," + + " instead found ${_withArgsCreator.annotated.javaClass.name}" + ) } // we cannot reflect this method so do the default Java-ish behavior fun checkConstructorIsCreatorAnnotated(key: AnnotatedConstructor, calc: (AnnotatedConstructor) -> Boolean): Boolean = javaConstructorIsCreatorAnnotated.get(key)