Skip to content

Commit 08e408b

Browse files
christophstroblmp911de
authored andcommitted
Use NativeDetector.inNativeImage() instead of manual property check.
Closes: #2298 Original pull request: #2299. Relates to: spring-projects/spring-framework#25795
1 parent b615a20 commit 08e408b

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.context.ApplicationEventPublisher;
3939
import org.springframework.context.ApplicationEventPublisherAware;
4040
import org.springframework.core.KotlinDetector;
41+
import org.springframework.core.NativeDetector;
4142
import org.springframework.data.mapping.MappingException;
4243
import org.springframework.data.mapping.PersistentEntity;
4344
import org.springframework.data.mapping.PersistentProperty;
@@ -86,8 +87,6 @@
8687
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?, P>, P extends PersistentProperty<P>>
8788
implements MappingContext<E, P>, ApplicationEventPublisherAware, ApplicationContextAware, InitializingBean {
8889

89-
private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
90-
9190
private final Optional<E> NONE = Optional.empty();
9291
private final Map<TypeInformation<?>, Optional<E>> persistentEntities = new HashMap<>();
9392
private final PersistentPropertyAccessorFactory persistentPropertyAccessorFactory;
@@ -109,7 +108,7 @@ protected AbstractMappingContext() {
109108
this.persistentPropertyPathFactory = new PersistentPropertyPathFactory<>(this);
110109

111110
EntityInstantiators instantiators = new EntityInstantiators();
112-
PersistentPropertyAccessorFactory accessorFactory = IN_NATIVE_IMAGE ? BeanWrapperPropertyAccessorFactory.INSTANCE
111+
PersistentPropertyAccessorFactory accessorFactory = NativeDetector.inNativeImage() ? BeanWrapperPropertyAccessorFactory.INSTANCE
113112
: new ClassGeneratingPropertyAccessorFactory();
114113

115114
this.persistentPropertyAccessorFactory = new InstantiationAwarePropertyAccessorFactory(accessorFactory,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.asm.Opcodes;
3232
import org.springframework.asm.Type;
3333
import org.springframework.cglib.core.ReflectUtils;
34+
import org.springframework.core.NativeDetector;
3435
import org.springframework.data.mapping.PersistentEntity;
3536
import org.springframework.data.mapping.PersistentProperty;
3637
import org.springframework.data.mapping.PreferredConstructor;
@@ -55,7 +56,6 @@
5556
class ClassGeneratingEntityInstantiator implements EntityInstantiator {
5657

5758
private static final Log LOGGER = LogFactory.getLog(ClassGeneratingEntityInstantiator.class);
58-
private static final boolean IN_NATIVE_IMAGE = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
5959

6060
private static final Object[] EMPTY_ARGS = new Object[0];
6161

@@ -142,7 +142,7 @@ protected EntityInstantiator doCreateEntityInstantiator(PersistentEntity<?, ?> e
142142
*/
143143
boolean shouldUseReflectionEntityInstantiator(PersistentEntity<?, ?> entity) {
144144

145-
if (IN_NATIVE_IMAGE) {
145+
if (NativeDetector.inNativeImage()) {
146146

147147
if (LOGGER.isDebugEnabled()) {
148148
LOGGER.debug(String.format("graalvm.nativeimage - fall back to reflection for %s.", entity.getName()));

0 commit comments

Comments
 (0)