-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
ClassUtil
fails with java.lang.reflect.InaccessibleObjectException
trying to setAccessible on OptionalInt
with JDK 17+
#4082
Comments
If you want to use OptionalInt, you should register this module -> https://github.com/FasterXML/jackson-modules-java8 If you continue to get issues like this, you might need to use the Java command line option |
ClassUtil
fails with java.lang.reflect.InaccessibleObjectException
trying to setAccessible on OptionalInt
with JDK 17+
@pjfanning is correct in pointing out need for JDK8 types module. But I think we could also add block in |
Hello Tatu and @pjfanning, thank you for looking into this.
The use of OptionalInt in this reproducer was just an example where the ClassUtil ended up trying to |
I gave this a quick try in that trivial reproducer by registering this module as explained in https://github.com/FasterXML/jackson-modules-java8/tree/2.15/datatypes#readme and that does indeed help. I no longer see any reflection access related exceptions being thrown in Java 17+, which is understandable because looking at the implementation in the So I think it's now a matter of deciding whether in the absence of this module registration, would it be possible to prevent calling |
If this means adding jackson-databind/src/main/java/com/fasterxml/jackson/databind/util/BeanUtil.java Line 297 in 7f85d4a
... this method to provide meaningful exception message, +1️⃣. EDITED : I will come back later and work on this if it has not been done yet. |
I am working on a PoC solution here. |
Jackson adapted handling for Optional serialization providing a custom exception message if Optional is being serialized. Scout does not support serialization of Java Optional, therefore adapt test case. See FasterXML/jackson-databind#4082 FasterXML/jackson-databind@d7e77c3
Jackson adapted handling for Optional serialization providing a custom exception message if Optional is being serialized. Scout does not support serialization of Java Optional, therefore adapt test case. See FasterXML/jackson-databind#4082 FasterXML/jackson-databind@d7e77c3
Jackson adapted handling for Optional serialization providing a custom exception message if Optional is being serialized. Scout does not support serialization of Java Optional, therefore adapt test case. See FasterXML/jackson-databind#4082 FasterXML/jackson-databind@d7e77c3
(1) Jackson adapted handling for Optional serialization providing a custom exception message if Optional is being serialized. Scout does not support serialization of Java Optional, therefore adapt test case. See also: FasterXML/jackson-databind#4082 FasterXML/jackson-databind@d7e77c3 (2) Jackson adapted handling for untyped deserialization of floating point numbers. Former implementations (before 2.15) deserialized floating point numbers within lists as BigDecimal. Since issue 903 and 3751 numbers are deserialized into the smalles possible Java data type (same behavior as plain numbers not within a JSON list element). Therefore Scout DoCollectionDeserializer was adapted identically to DoEntityDeserializer to enforce using BigDecimal for unknown (raw) number deserialization. See also: FasterXML/jackson-core#903 FasterXML/jackson-core@4c957e3 and FasterXML/jackson-databind#3751 FasterXML/jackson-databind@23ea48c
(1) Jackson adapted handling for Optional serialization providing a custom exception message if Optional is being serialized. Scout does not support serialization of Java Optional, therefore adapt test case. See also: FasterXML/jackson-databind#4082 FasterXML/jackson-databind@d7e77c3 (2) Jackson adapted handling for untyped deserialization of floating point numbers. Former implementations (before 2.15) deserialized floating point numbers within lists as BigDecimal. Since issue 903 and 3751 numbers are deserialized into the smalles possible Java data type (same behavior as plain numbers not within a JSON list element). Therefore Scout DoCollectionDeserializer was adapted identically to DoEntityDeserializer to enforce using BigDecimal for unknown (raw) number deserialization. See also: FasterXML/jackson-core#903 FasterXML/jackson-core@4c957e3 and FasterXML/jackson-databind#3751 FasterXML/jackson-databind@23ea48c
(1) Jackson adapted handling for Optional serialization providing a custom exception message if Optional is being serialized. Scout does not support serialization of Java Optional, therefore adapt test case. See also: FasterXML/jackson-databind#4082 FasterXML/jackson-databind@d7e77c3 (2) Jackson adapted handling for untyped deserialization of floating point numbers. Former implementations (before 2.15) deserialized floating point numbers within lists as BigDecimal. Since issue 903 and 3751 numbers are deserialized into the smalles possible Java data type (same behavior as plain numbers not within a JSON list element). Therefore Scout DoCollectionDeserializer was adapted identically to DoEntityDeserializer to enforce using BigDecimal for unknown (raw) number deserialization. See also: FasterXML/jackson-core#903 FasterXML/jackson-core@4c957e3 and FasterXML/jackson-databind#3751 FasterXML/jackson-databind@23ea48c
(1) Jackson adapted handling for Optional serialization providing a custom exception message if Optional is being serialized. Scout does not support serialization of Java Optional, therefore adapt test case. See also: FasterXML/jackson-databind#4082 FasterXML/jackson-databind@d7e77c3 (2) Jackson adapted handling for untyped deserialization of floating point numbers. Former implementations (before 2.15) deserialized floating point numbers within lists as BigDecimal. Since issue 903 and 3751 numbers are deserialized into the smalles possible Java data type (same behavior as plain numbers not within a JSON list element). Therefore Scout DoCollectionDeserializer was adapted identically to DoEntityDeserializer to enforce using BigDecimal for unknown (raw) number deserialization. See also: FasterXML/jackson-core#903 FasterXML/jackson-core@4c957e3 and FasterXML/jackson-databind#3751 FasterXML/jackson-databind@23ea48c 354734
(1) Jackson adapted handling for Optional serialization providing a custom exception message if Optional is being serialized. Scout does not support serialization of Java Optional, therefore adapt test case. See also: FasterXML/jackson-databind#4082 FasterXML/jackson-databind@d7e77c3 (2) Jackson adapted handling for untyped deserialization of floating point numbers. Former implementations (before 2.15) deserialized floating point numbers within lists as BigDecimal. Since issue 903 and 3751 numbers are deserialized into the smalles possible Java data type (same behavior as plain numbers not within a JSON list element). Therefore Scout DoCollectionDeserializer was adapted identically to DoEntityDeserializer to enforce using BigDecimal for unknown (raw) number deserialization. See also: FasterXML/jackson-core#903 FasterXML/jackson-core@4c957e3 and FasterXML/jackson-databind#3751 FasterXML/jackson-databind@23ea48c 354734
(1) Jackson adapted handling for Optional serialization providing a custom exception message if Optional is being serialized. Scout does not support serialization of Java Optional, therefore adapt test case. See also: FasterXML/jackson-databind#4082 FasterXML/jackson-databind@d7e77c3 (2) Jackson adapted handling for untyped deserialization of floating point numbers. Former implementations (before 2.15) deserialized floating point numbers within lists as BigDecimal. Since issue 903 and 3751 numbers are deserialized into the smalles possible Java data type (same behavior as plain numbers not within a JSON list element). Therefore Scout DoCollectionDeserializer was adapted identically to DoEntityDeserializer to enforce using BigDecimal for unknown (raw) number deserialization. See also: FasterXML/jackson-core#903 FasterXML/jackson-core@4c957e3 and FasterXML/jackson-databind#3751 FasterXML/jackson-databind@23ea48c 354734
(1) Jackson adapted handling for Optional serialization providing a custom exception message if Optional is being serialized. Scout does not support serialization of Java Optional, therefore adapt test case. See also: FasterXML/jackson-databind#4082 FasterXML/jackson-databind@d7e77c3 (2) Jackson adapted handling for untyped deserialization of floating point numbers. Former implementations (before 2.15) deserialized floating point numbers within lists as BigDecimal. Since issue 903 and 3751 numbers are deserialized into the smalles possible Java data type (same behavior as plain numbers not within a JSON list element). Therefore Scout DoCollectionDeserializer was adapted identically to DoEntityDeserializer to enforce using BigDecimal for unknown (raw) number deserialization. See also: FasterXML/jackson-core#903 FasterXML/jackson-core@4c957e3 and FasterXML/jackson-databind#3751 FasterXML/jackson-databind@23ea48c 354734, 371286
(1) Jackson adapted handling for Optional serialization providing a custom exception message if Optional is being serialized. Scout does not support serialization of Java Optional, therefore adapt test case. See also: FasterXML/jackson-databind#4082 FasterXML/jackson-databind@d7e77c3 (2) Jackson adapted handling for untyped deserialization of floating point numbers. Former implementations (before 2.15) deserialized floating point numbers within lists as BigDecimal. Since issue 903 and 3751 numbers are deserialized into the smalles possible Java data type (same behavior as plain numbers not within a JSON list element). Therefore Scout DoCollectionDeserializer was adapted identically to DoEntityDeserializer to enforce using BigDecimal for unknown (raw) number deserialization. See also: FasterXML/jackson-core#903 FasterXML/jackson-core@4c957e3 and FasterXML/jackson-databind#3751 FasterXML/jackson-databind@23ea48c 354734, 371286
Search before asking
Describe the bug
Please consider the following trivial Java code:
When using
jackson-databind
2.15.2
and Java version 17 and running this program, it results in:So
com.fasterxml.jackson.databind.util.ClassUtil
is trying tosetAccessible()
on the private constructor of a JDK classjava.util.OptionalInt
. One way to solve this issue is to configure theObjectMapper
instance as follows:However, while looking at the code in
com.fasterxml.jackson.databind.util.ClassUtil
I noticed that there's a specific logic which tries to notsetAccessible()
on JDK internal classes here https://github.com/FasterXML/jackson-databind/blob/jackson-databind-2.15.2/src/main/java/com/fasterxml/jackson/databind/util/ClassUtil.java#L994 which looks like:Should that
!isJDKClass(declaringClass)
be perhaps applied even whenevenIfAlreadyPublic
is false? Something like:That way, it won't try to access the internal JDK classes and run into these exceptions on Java 17+?
Version Information
2.15.2
Reproduction
No response
Expected behavior
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: