Skip to content

Commit 11787a4

Browse files
committed
Fix generics
UNCHECKED_CAST was required throughout and was not contributing to improved safety.
1 parent b917694 commit 11787a4

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinAnnotationIntrospector.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ internal class KotlinAnnotationIntrospector(
9595
if (!useJavaDurationConversion) return null
9696

9797
return (a as? AnnotatedParameter)?.let { param ->
98-
@Suppress("UNCHECKED_CAST")
9998
val function: KFunction<*> = when (val owner = param.owner.member) {
100-
is Constructor<*> -> cache.kotlinFromJava(owner as Constructor<Any>)
99+
is Constructor<*> -> cache.kotlinFromJava(owner)
101100
is Method -> cache.kotlinFromJava(owner)
102101
else -> null
103102
} ?: return@let null

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,12 @@ internal class KotlinNamesAnnotationIntrospector(
7979
}
8080
}
8181

82-
@Suppress("UNCHECKED_CAST")
8382
private fun hasCreatorAnnotation(member: AnnotatedConstructor): Boolean {
8483
// don't add a JsonCreator to any constructor if one is declared already
8584

8685
val kClass = member.declaringClass.kotlin
8786
.apply { if (this in ignoredClassesForImplyingJsonCreator) return false }
88-
val kConstructor = cache.kotlinFromJava(member.annotated as Constructor<Any>) ?: return false
87+
val kConstructor = cache.kotlinFromJava(member.annotated) ?: return false
8988

9089
// TODO: should we do this check or not? It could cause failures if we miss another way a property could be set
9190
// val requiredProperties = kClass.declaredMemberProperties.filter {!it.returnType.isMarkedNullable }.map { it.name }.toSet()

src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal class ReflectionCache(reflectionCacheSize: Int) : Serializable {
4242
}
4343
}
4444

45-
private val javaConstructorToKotlin = LRUMap<Constructor<Any>, KFunction<Any>>(reflectionCacheSize, reflectionCacheSize)
45+
private val javaConstructorToKotlin = LRUMap<Constructor<*>, KFunction<*>>(reflectionCacheSize, reflectionCacheSize)
4646
private val javaMethodToKotlin = LRUMap<Method, KFunction<*>>(reflectionCacheSize, reflectionCacheSize)
4747
private val javaExecutableToValueCreator = LRUMap<Executable, ValueCreator<*>>(reflectionCacheSize, reflectionCacheSize)
4848
private val javaConstructorIsCreatorAnnotated = LRUMap<AnnotatedConstructor, Boolean>(reflectionCacheSize, reflectionCacheSize)
@@ -57,7 +57,7 @@ internal class ReflectionCache(reflectionCacheSize: Int) : Serializable {
5757
private val valueClassBoxConverterCache: LRUMap<KClass<*>, ValueClassBoxConverter<*, *>> =
5858
LRUMap(0, reflectionCacheSize)
5959

60-
fun kotlinFromJava(key: Constructor<Any>): KFunction<Any>? = javaConstructorToKotlin.get(key)
60+
fun kotlinFromJava(key: Constructor<*>): KFunction<*>? = javaConstructorToKotlin.get(key)
6161
?: key.kotlinFunction?.let { javaConstructorToKotlin.putIfAbsent(key, it) ?: it }
6262

6363
fun kotlinFromJava(key: Method): KFunction<*>? = javaMethodToKotlin.get(key)

0 commit comments

Comments
 (0)