Skip to content
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

Jackson IT tries to reflectively access non-registered declaredFields of classes #45537

Open
zakkak opened this issue Jan 13, 2025 · 8 comments
Labels
area/jackson Issues related to Jackson (JSON library) area/native-image kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus.

Comments

@zakkak
Copy link
Contributor

zakkak commented Jan 13, 2025

Describe the bug

Jackson IT tries to reflectively access declaredFields, declaredMethods, and declaredConstructors of classes which are not registered for reflection.

Relates to #41995

Expected behavior

All integration tests should not be accessing elements that are not explicitly registered for reflection in native mode.

Actual behavior

jackson integration test tries to reflectively access declaredFields, declaredMethods, and declaredConstructors of java.util.Date resulting in an exception when using -H:ThrowMissingRegistrationErrors=

org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.util.Date.getDeclaredFields()

without it being registered for runtime reflection. Add java.util.Date.getDeclaredFields() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@25/java.lang.Class.getDeclaredFields(DynamicHub.java:1416)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector._findFields(AnnotatedFieldCollector.java:73)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector._findFields(AnnotatedFieldCollector.java:71)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector.collect(AnnotatedFieldCollector.java:48)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector.collectFields(AnnotatedFieldCollector.java:43)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass._fields(AnnotatedClass.java:370)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass.fields(AnnotatedClass.java:342)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addFields(POJOPropertiesCollector.java:527)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:442)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:269)
  com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:248)
  com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:393)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:174)
  com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1523)
  com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1471)
  com.fasterxml.jackson.databind.SerializerProvider.findPrimaryPropertySerializer(SerializerProvider.java:739)
  com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddPrimarySerializer(PropertySerializerMap.java:64)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter._findAndAddDynamic(BeanPropertyWriter.java:901)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:710)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.sql.Date.getDeclaredFields()

without it being registered for runtime reflection. Add java.sql.Date.getDeclaredFields() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@25/java.lang.Class.getDeclaredFields(DynamicHub.java:1416)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector._findFields(AnnotatedFieldCollector.java:73)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector.collect(AnnotatedFieldCollector.java:48)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector.collectFields(AnnotatedFieldCollector.java:43)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass._fields(AnnotatedClass.java:370)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass.fields(AnnotatedClass.java:342)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addFields(POJOPropertiesCollector.java:527)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:442)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:269)
  com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:248)
  com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:393)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:174)
  com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1523)
  com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1471)
  com.fasterxml.jackson.databind.SerializerProvider.findPrimaryPropertySerializer(SerializerProvider.java:739)
  com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddPrimarySerializer(PropertySerializerMap.java:64)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter._findAndAddDynamic(BeanPropertyWriter.java:901)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:710)
  com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.sql.Date.getDeclaredMethods()

without it being registered for runtime reflection. Add java.sql.Date.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@25/java.lang.Class.getDeclaredMethods(DynamicHub.java:1423)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:49)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collectMethods(AnnotatedMethodCollector.java:40)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass._methods(AnnotatedClass.java:386)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass.memberMethods(AnnotatedClass.java:326)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addMethods(POJOPropertiesCollector.java:1073)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:444)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:269)
  com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:248)
  com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:393)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:174)
  com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1523)
  com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1471)
  com.fasterxml.jackson.databind.SerializerProvider.findPrimaryPropertySerializer(SerializerProvider.java:739)
  com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddPrimarySerializer(PropertySerializerMap.java:64)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter._findAndAddDynamic(BeanPropertyWriter.java:901)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:710)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.util.Date.getDeclaredMethods()

without it being registered for runtime reflection. Add java.util.Date.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@25/java.lang.Class.getDeclaredMethods(DynamicHub.java:1423)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:54)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collectMethods(AnnotatedMethodCollector.java:40)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass._methods(AnnotatedClass.java:386)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass.memberMethods(AnnotatedClass.java:326)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addMethods(POJOPropertiesCollector.java:1073)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:444)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:269)
  com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:248)
  com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:393)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:174)
  com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1523)
  com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1471)
  com.fasterxml.jackson.databind.SerializerProvider.findPrimaryPropertySerializer(SerializerProvider.java:739)
  com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddPrimarySerializer(PropertySerializerMap.java:64)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter._findAndAddDynamic(BeanPropertyWriter.java:901)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:710)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.io.Serializable.getDeclaredMethods()

without it being registered for runtime reflection. Add java.io.Serializable.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@25/java.lang.Class.getDeclaredMethods(DynamicHub.java:1423)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:54)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collectMethods(AnnotatedMethodCollector.java:40)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass._methods(AnnotatedClass.java:386)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass.memberMethods(AnnotatedClass.java:326)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addMethods(POJOPropertiesCollector.java:1073)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:444)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:269)
  com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:248)
  com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:393)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:174)
  com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1523)
  com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1471)
  com.fasterxml.jackson.databind.SerializerProvider.findPrimaryPropertySerializer(SerializerProvider.java:739)
  com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddPrimarySerializer(PropertySerializerMap.java:64)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter._findAndAddDynamic(BeanPropertyWriter.java:901)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:710)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.lang.Cloneable.getDeclaredMethods()

without it being registered for runtime reflection. Add java.lang.Cloneable.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@25/java.lang.Class.getDeclaredMethods(DynamicHub.java:1423)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:54)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collectMethods(AnnotatedMethodCollector.java:40)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass._methods(AnnotatedClass.java:386)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass.memberMethods(AnnotatedClass.java:326)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addMethods(POJOPropertiesCollector.java:1073)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:444)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:269)
  com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:248)
  com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:393)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:174)
  com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1523)
  com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1471)
  com.fasterxml.jackson.databind.SerializerProvider.findPrimaryPropertySerializer(SerializerProvider.java:739)
  com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddPrimarySerializer(PropertySerializerMap.java:64)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter._findAndAddDynamic(BeanPropertyWriter.java:901)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:710)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.lang.Comparable.getDeclaredMethods()

without it being registered for runtime reflection. Add java.lang.Comparable.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@25/java.lang.Class.getDeclaredMethods(DynamicHub.java:1423)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:54)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collectMethods(AnnotatedMethodCollector.java:40)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass._methods(AnnotatedClass.java:386)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass.memberMethods(AnnotatedClass.java:326)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addMethods(POJOPropertiesCollector.java:1073)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:444)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:269)
  com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:248)
  com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:393)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:174)
  com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1523)
  com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1471)
  com.fasterxml.jackson.databind.SerializerProvider.findPrimaryPropertySerializer(SerializerProvider.java:739)
  com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddPrimarySerializer(PropertySerializerMap.java:64)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter._findAndAddDynamic(BeanPropertyWriter.java:901)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:710)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.sql.Date.getDeclaredConstructors()

without it being registered for runtime reflection. Add java.sql.Date.getDeclaredConstructors() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@25/java.lang.Class.getDeclaredConstructors(DynamicHub.java:1429)
  com.fasterxml.jackson.databind.util.ClassUtil.getConstructors(ClassUtil.java:1345)
  com.fasterxml.jackson.databind.introspect.AnnotatedCreatorCollector._findPotentialConstructors(AnnotatedCreatorCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedCreatorCollector.collect(AnnotatedCreatorCollector.java:70)
  com.fasterxml.jackson.databind.introspect.AnnotatedCreatorCollector.collectCreators(AnnotatedCreatorCollector.java:61)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass._creators(AnnotatedClass.java:402)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass.getConstructors(AnnotatedClass.java:307)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addCreators(POJOPropertiesCollector.java:656)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:451)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:269)
  com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:248)
  com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:393)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:174)
  com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1523)
  com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1471)
  com.fasterxml.jackson.databind.SerializerProvider.findPrimaryPropertySerializer(SerializerProvider.java:739)
  com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddPrimarySerializer(PropertySerializerMap.java:64)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter._findAndAddDynamic(BeanPropertyWriter.java:901)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:710)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.sql.Date.getDeclaredMethods()

without it being registered for runtime reflection. Add java.sql.Date.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@25/java.lang.Class.getDeclaredMethods(DynamicHub.java:1423)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedCreatorCollector._findPotentialFactories(AnnotatedCreatorCollector.java:197)
  com.fasterxml.jackson.databind.introspect.AnnotatedCreatorCollector.collect(AnnotatedCreatorCollector.java:71)
  com.fasterxml.jackson.databind.introspect.AnnotatedCreatorCollector.collectCreators(AnnotatedCreatorCollector.java:61)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass._creators(AnnotatedClass.java:402)
  com.fasterxml.jackson.databind.introspect.AnnotatedClass.getConstructors(AnnotatedClass.java:307)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addCreators(POJOPropertiesCollector.java:656)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:451)
  com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:269)
  com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:248)
  com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:393)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225)
  com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:174)
  com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1523)
  com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1471)
  com.fasterxml.jackson.databind.SerializerProvider.findPrimaryPropertySerializer(SerializerProvider.java:739)
  com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddPrimarySerializer(PropertySerializerMap.java:64)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter._findAndAddDynamic(BeanPropertyWriter.java:901)
  com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:710)

How to Reproduce?

./mvnw clean package -Dnative -Dnative.surefire.skip \
  -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-23 \
  -pl integration-tests/jackson/ \
  -Dquarkus.native.additional-build-args=-H:ThrowMissingRegistrationErrors=

./integration-tests/jackson/target/quarkus-integration-test-jackson-999-SNAPSHOT-runner \
  -XX:MissingRegistrationReportingMode=Warn

On another terminal

curl -H 'content-type: text/plain' \
  -d '{"date":"1970-01-01"}' \
  'http://localhost:8080/datedeserializers/sql/date'

Output of uname -a or ver

No response

Output of java -version

No response

Mandrel or GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@zakkak zakkak added area/native-image kind/bug Something isn't working labels Jan 13, 2025
@quarkus-bot quarkus-bot bot added the area/jackson Issues related to Jackson (JSON library) label Jan 13, 2025
Copy link

quarkus-bot bot commented Jan 13, 2025

/cc @Karm (native-image), @galderz (native-image), @geoand (jackson), @gsmet (jackson), @mariofusco (jackson)

@zakkak
Copy link
Contributor Author

zakkak commented Jan 13, 2025

Since java.sql.Date is a subclass of java.util.Date I suspect that Quarkus should be registering the whole class hierarchy.

@zakkak zakkak changed the title Jackson IT tries to reflectively access declaredFields of java.util.Date Jackson IT tries to reflectively access non-registered declaredFields of classes Jan 13, 2025
@gsmet
Copy link
Member

gsmet commented Jan 13, 2025

My guess is that the issue is here:

private static final List<String> DEFAULT_IGNORED_PACKAGES = Arrays.asList("java.", "io.reactivex.",
"org.reactivestreams.", "org.slf4j.", "jakarta.", "jakarta.json.",
"javax.net.ssl.", "javax.xml.", "javax.management.", "reactor.core.",
"com.fasterxml.jackson.databind.", "io.vertx.core.json.", "kotlin.");
// if this gets more complicated we will need to move to some tree like structure
static final Set<String> ALLOWED_FROM_IGNORED_PACKAGES = new HashSet<>(
Arrays.asList("java.math.BigDecimal", "java.math.BigInteger"));

But from what I can see, it's a lot more than just java.util.Date, I also have java.lang.Cloneable, java.lang.Comparable, java.sql.Date.

My guess is that we probably have to reconsider the whole java exclusion... but... we need to be extremely careful of what ends up being registered additionally.

@gsmet
Copy link
Member

gsmet commented Jan 13, 2025

@cowtowncoder is there a chance Jackson's own AnnotatedFieldCollector/AnnotatedMethodCollector/AnnotatedCreatorCollector brings something useful for classes in the java.* packages? Should Jackson not collect the information there?

Here is the full output:

org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.util.Date.getDeclaredFields()

without it being registered for runtime reflection. Add java.util.Date.getDeclaredFields() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  [email protected]/java.lang.Class.getDeclaredFields(DynamicHub.java:1251)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector._findFields(AnnotatedFieldCollector.java:73)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector._findFields(AnnotatedFieldCollector.java:71)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector.collect(AnnotatedFieldCollector.java:48)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.sql.Date.getDeclaredFields()

without it being registered for runtime reflection. Add java.sql.Date.getDeclaredFields() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  [email protected]/java.lang.Class.getDeclaredFields(DynamicHub.java:1251)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector._findFields(AnnotatedFieldCollector.java:73)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector.collect(AnnotatedFieldCollector.java:48)
  com.fasterxml.jackson.databind.introspect.AnnotatedFieldCollector.collectFields(AnnotatedFieldCollector.java:43)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.sql.Date.getDeclaredMethods()

without it being registered for runtime reflection. Add java.sql.Date.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  [email protected]/java.lang.Class.getDeclaredMethods(DynamicHub.java:1258)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:49)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.util.Date.getDeclaredMethods()

without it being registered for runtime reflection. Add java.util.Date.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  [email protected]/java.lang.Class.getDeclaredMethods(DynamicHub.java:1258)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:54)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.io.Serializable.getDeclaredMethods()

without it being registered for runtime reflection. Add java.io.Serializable.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  [email protected]/java.lang.Class.getDeclaredMethods(DynamicHub.java:1258)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:54)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.lang.Cloneable.getDeclaredMethods()

without it being registered for runtime reflection. Add java.lang.Cloneable.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  [email protected]/java.lang.Class.getDeclaredMethods(DynamicHub.java:1258)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:54)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.lang.Comparable.getDeclaredMethods()

without it being registered for runtime reflection. Add java.lang.Comparable.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  [email protected]/java.lang.Class.getDeclaredMethods(DynamicHub.java:1258)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:54)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.sql.Date.getDeclaredConstructors()

without it being registered for runtime reflection. Add java.sql.Date.getDeclaredConstructors() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  [email protected]/java.lang.Class.getDeclaredConstructors(DynamicHub.java:1264)
  com.fasterxml.jackson.databind.util.ClassUtil.getConstructors(ClassUtil.java:1345)
  com.fasterxml.jackson.databind.introspect.AnnotatedCreatorCollector._findPotentialConstructors(AnnotatedCreatorCollector.java:115)
  com.fasterxml.jackson.databind.introspect.AnnotatedCreatorCollector.collect(AnnotatedCreatorCollector.java:70)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access

   java.sql.Date.getDeclaredMethods()

without it being registered for runtime reflection. Add java.sql.Date.getDeclaredMethods() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  [email protected]/java.lang.Class.getDeclaredMethods(DynamicHub.java:1258)
  com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1300)
  com.fasterxml.jackson.databind.introspect.AnnotatedCreatorCollector._findPotentialFactories(AnnotatedCreatorCollector.java:197)
  com.fasterxml.jackson.databind.introspect.AnnotatedCreatorCollector.collect(AnnotatedCreatorCollector.java:71)

@cowtowncoder
Copy link

@gsmet So, over time I have tried to limit amount of introspection to java.* packages, over time -- earlier they were introspected 100% same as anything else (i.e. there was no special handling).
I think we have some concerns about dropping all introspection since it seems possible some discovery allows for handling of JDK types (mostly static valueOf() factory methods or trivial POJO style handling), but I think ideally only explicit support (explicit (de)serializers) would be supported.
Similarly, use of mix-in annotations on java.* types (to make (de)serialization work POJO style) might require introspection. But that maybe something that just isn't supportable in future.

Could you file an issue on jackson-databind requesting reducing introspection of java.* types, with some of examples from above (and link to this issue)?
I think it'd be good to see what more can be removed.

There are likely some cases where introspection is still needed (EnumSet and/or EnumMap require something for type detection as I recall), but wide-spread access shouldn't really be neeed.

@mariofusco
Copy link
Contributor

@cowtowncoder My personal suggestion is to completely remove any attempt of introspection for classes belonging to java.* packages. I believe it's at best a wasted effort 99% of time. And for the few cases where this could be really necessary (like for the EnumSet and/or EnumMap that you mentioned, btw can you point me to some special treatment for those classes if any or some test case demonstrating how this works? I'm curious of this use case and at the moment I don't understand this need) we could "hardcode" the result of the possible introspection thus also having the twofold advantage of a performance gain and the possibility to finely customize the list of fields that we want to serialize for that class.

@gsmet
Copy link
Member

gsmet commented Jan 15, 2025

@cowtowncoder I created FasterXML/jackson-databind#4907, thanks for the feedback!

@gsmet gsmet added kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus. and removed kind/bug Something isn't working labels Jan 15, 2025
@cowtowncoder
Copy link

cowtowncoder commented Jan 15, 2025

@mariofusco If I was writing things from scratch, no doubt it'd best to avoid introspection. My problem is that since it is there, removal is very likely to cause some breakage somewhere. Unit test suite may catch some things but if the past experience is any indication it won't catch all cases everyone has.

So "just remove it" is generally a sure recipe for trouble.

As to EnumSet / EnumMap I don't have time to dig into it but I think ClassUtil has some functionality called when constructing deserializers for these 2 types (I think it's actually really just one of them and I never remember which one).

All of this is just to say that it's necessary to proceed incrementally: maybe disabling introspection works just fine. But we have had so many bugs introduced by "just doing it" kinds of changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/jackson Issues related to Jackson (JSON library) area/native-image kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus.
Projects
None yet
Development

No branches or pull requests

4 participants