From 7ed72ff41fc2a52fc6d2e44aa022d082352eb146 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Mon, 13 Jul 2020 12:33:33 +0200 Subject: [PATCH] DATACMNS-1767 - Disable ClassGeneratingEntityInstantiator when running native-image. Always fall back to reflection when the system property for org.graalvm.nativeimage.imagecode is set. This is required because on the fly code generation is not supported in this case. Original pull request: #456. --- .../model/ClassGeneratingEntityInstantiator.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiator.java b/src/main/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiator.java index d24186290..a80ad577d 100644 --- a/src/main/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiator.java +++ b/src/main/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiator.java @@ -24,6 +24,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.asm.ClassWriter; import org.springframework.asm.MethodVisitor; import org.springframework.asm.Opcodes; @@ -52,6 +54,9 @@ import org.springframework.util.ClassUtils; */ class ClassGeneratingEntityInstantiator implements EntityInstantiator { + private static final Log LOGGER = LogFactory.getLog(ClassGeneratingEntityInstantiator.class); + private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null; + private static final Object[] EMPTY_ARGS = new Object[0]; private final ObjectInstantiatorClassGenerator generator; @@ -137,6 +142,15 @@ class ClassGeneratingEntityInstantiator implements EntityInstantiator { */ boolean shouldUseReflectionEntityInstantiator(PersistentEntity entity) { + if(IN_NATIVE_IMAGE) { + + if(LOGGER.isDebugEnabled()) { + LOGGER.debug(String.format("graalvm.nativeimage - fall back to reflection for %s.", entity.getName())); + } + + return true; + } + Class type = entity.getType(); if (type.isInterface() //