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.
This commit is contained in:
Christoph Strobl
2020-07-13 12:33:33 +02:00
committed by Mark Paluch
parent e19bdb8fc4
commit ff0a8f77e8

View File

@@ -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() //