Skip to content

Commit ff0a8f7

Browse files
christophstroblmp911de
authored andcommitted
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.
1 parent e19bdb8 commit ff0a8f7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/main/java/org/springframework/data/mapping/model/ClassGeneratingEntityInstantiator.java

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27+
import org.apache.commons.logging.Log;
28+
import org.apache.commons.logging.LogFactory;
2729
import org.springframework.asm.ClassWriter;
2830
import org.springframework.asm.MethodVisitor;
2931
import org.springframework.asm.Opcodes;
@@ -52,6 +54,9 @@
5254
*/
5355
class ClassGeneratingEntityInstantiator implements EntityInstantiator {
5456

57+
private static final Log LOGGER = LogFactory.getLog(ClassGeneratingEntityInstantiator.class);
58+
private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
59+
5560
private static final Object[] EMPTY_ARGS = new Object[0];
5661

5762
private final ObjectInstantiatorClassGenerator generator;
@@ -137,6 +142,15 @@ protected EntityInstantiator doCreateEntityInstantiator(PersistentEntity<?, ?> e
137142
*/
138143
boolean shouldUseReflectionEntityInstantiator(PersistentEntity<?, ?> entity) {
139144

145+
if(IN_NATIVE_IMAGE) {
146+
147+
if(LOGGER.isDebugEnabled()) {
148+
LOGGER.debug(String.format("graalvm.nativeimage - fall back to reflection for %s.", entity.getName()));
149+
}
150+
151+
return true;
152+
}
153+
140154
Class<?> type = entity.getType();
141155

142156
if (type.isInterface() //

0 commit comments

Comments
 (0)