Skip to content

Fixed to use common util for Member accessibility override #944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Contributors:
# 2.19.0 (not yet released)

WrongWrong (@k163377)
* #944: Fixed to use common util for Member accessibility override
* #937: Added type match check to read functions

Tatu Saloranta (@cowtowncoder)
Expand Down
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Co-maintainers:

2.19.0 (not yet released)

#944: Common util is now used for member accessibility overrides.
#937: For `readValue` and other shorthands for `ObjectMapper` deserialization methods,
type consistency checks have been added.
A `RuntimeJsonMappingException` will be thrown in case of inconsistency.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JavaType
import com.fasterxml.jackson.databind.deser.std.StdDelegatingDeserializer
import com.fasterxml.jackson.databind.ser.std.StdDelegatingSerializer
import com.fasterxml.jackson.databind.type.TypeFactory
import com.fasterxml.jackson.databind.util.ClassUtil
import com.fasterxml.jackson.databind.util.StdConverter
import kotlin.reflect.KClass
import kotlin.time.toJavaDuration
Expand Down Expand Up @@ -51,7 +52,7 @@ internal class ValueClassBoxConverter<S : Any?, D : Any>(
val boxedClass: KClass<D>
) : StdConverter<S, D>() {
private val boxMethod = boxedClass.java.getDeclaredMethod("box-impl", unboxedClass).apply {
if (!this.isAccessible) this.isAccessible = true
ClassUtil.checkAndFixAccess(this, false)
}

@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.deser.Deserializers
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException
import com.fasterxml.jackson.databind.util.ClassUtil
import java.lang.reflect.Method
import java.lang.reflect.Modifier
import kotlin.reflect.full.primaryConstructor
Expand Down Expand Up @@ -106,7 +107,7 @@ internal class WrapsNullableValueClassBoxDeserializer<S, D : Any>(
private val inputType: Class<*> = creator.parameterTypes[0]

init {
creator.apply { if (!this.isAccessible) this.isAccessible = true }
ClassUtil.checkAndFixAccess(creator, false)
}

// Cache the result of wrapping null, since the result is always expected to be the same.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.*
import com.fasterxml.jackson.databind.deser.std.StdKeyDeserializer
import com.fasterxml.jackson.databind.deser.std.StdKeyDeserializers
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException
import com.fasterxml.jackson.databind.util.ClassUtil
import java.lang.reflect.Method
import kotlin.reflect.KClass
import kotlin.reflect.full.primaryConstructor
Expand Down Expand Up @@ -78,7 +79,7 @@ internal class ValueClassKeyDeserializer<S, D : Any>(
private val unboxedClass: Class<*> = creator.parameterTypes[0]

init {
creator.apply { if (!this.isAccessible) this.isAccessible = true }
ClassUtil.checkAndFixAccess(creator, false)
}

// Based on databind error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.module.kotlin

import com.fasterxml.jackson.databind.util.ClassUtil
import kotlin.reflect.KFunction
import kotlin.reflect.full.extensionReceiverParameter
import kotlin.reflect.full.instanceParameter
Expand Down Expand Up @@ -39,7 +40,7 @@ internal class MethodValueCreator<T> private constructor(
possibleCompanion.java.enclosingClass.declaredFields
.firstOrNull { it.type.kotlin.isCompanion }
?.let {
it.isAccessible = true
ClassUtil.checkAndFixAccess(it, false)

// If the instance of the companion object cannot be obtained, accessibility will always be false
it.get(null) to false
Expand Down