From 03860a4206b371adc19f3b7a21f410739c1e02d1 Mon Sep 17 00:00:00 2001 From: Loic Ottet Date: Tue, 1 Oct 2024 01:36:47 +0200 Subject: [PATCH] Consider all supertypes for serialization constructors --- .../svm/core/configure/SerializationMetadataParser.java | 2 +- .../hosted/reflect/serialize/SerializationFeature.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/SerializationMetadataParser.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/SerializationMetadataParser.java index 1f6a9f82221fa..1f6a32494a9fe 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/SerializationMetadataParser.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/SerializationMetadataParser.java @@ -65,7 +65,7 @@ protected void parseSerializationDescriptorObject(EconomicMap da Object optionalCustomCtorValue = data.get(CUSTOM_TARGET_CONSTRUCTOR_CLASS_KEY); if (optionalCustomCtorValue != null) { - RuntimeReflectionSupport.increaseCount(false); + RuntimeReflectionSupport.increaseCount(true); } registerType(targetSerializationClass.get(), condition.get(), optionalCustomCtorValue); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java index 2775baaf1d215..165e76c3700ec 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java @@ -553,9 +553,11 @@ public void registerWithTargetConstructorClass(ConfigurationCondition condition, return; } } - Optional.ofNullable(addConstructorAccessor(cnd, serializationTargetClass, customTargetConstructorClass)) - .map(ReflectionUtil::lookupConstructor) - .ifPresent(methods -> ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.alwaysTrue(), false, methods)); + for (Class superclass = serializationTargetClass.getSuperclass(); superclass != null; superclass = superclass.getSuperclass()) { + Optional.ofNullable(addConstructorAccessor(cnd, serializationTargetClass, superclass)) + .map(ReflectionUtil::lookupConstructor) + .ifPresent(methods -> ImageSingletons.lookup(RuntimeReflectionSupport.class).register(ConfigurationCondition.alwaysTrue(), false, methods)); + } Class superclass = serializationTargetClass.getSuperclass(); if (superclass != null) {