diff --git a/pom.xml b/pom.xml
index 5a7ea733bc..5b341c9610 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,6 +5,7 @@
org.springframework.data
spring-data-commons
+ 2.0.0.DATACMNS-1079-SNAPSHOT
Spring Data Core
diff --git a/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java b/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java
index 863232b548..33d59e83d7 100644
--- a/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java
+++ b/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java
@@ -101,15 +101,12 @@ public boolean isSupported(PersistentEntity, ?> entity) {
Assert.notNull(entity, "PersistentEntity must not be null!");
- try {
- Evil.getClassLoaderMethod(entity);
- } catch (Exception o_O) {
- return false;
- }
+ return isClassLoaderDefineClassAccessible(entity) //
+ && isTypeInjectable(entity) //
+ && arePropertyHashCodesUnique(entity);
+ }
- if (entity.getType().getClassLoader() == null || entity.getType().getPackage().getName().startsWith("java")) {
- return false;
- }
+ private boolean arePropertyHashCodesUnique(PersistentEntity, ?> entity) {
final Set hashCodes = new HashSet<>();
final AtomicInteger propertyCount = new AtomicInteger();
@@ -132,6 +129,20 @@ public boolean isSupported(PersistentEntity, ?> entity) {
return hashCodes.size() == propertyCount.get();
}
+ private static boolean isTypeInjectable(PersistentEntity, ?> entity) {
+ return entity.getType().getClassLoader() != null && !entity.getType().getPackage().getName().startsWith("java");
+ }
+
+ private static boolean isClassLoaderDefineClassAccessible(PersistentEntity, ?> entity) {
+
+ try {
+ Evil.getClassLoaderMethod(entity);
+ } catch (Exception o_O) {
+ return false;
+ }
+ return true;
+ }
+
/**
* @param entity must not be {@literal null}.
* @return
@@ -1463,7 +1474,6 @@ Class> defineClass(String name, byte[] bytes, int offset, int len, PersistentE
try {
Method defineClass = getClassLoaderMethod(persistentEntity);
- defineClass.setAccessible(true);
return (Class>) defineClass.invoke(classLoader, name, bytes, offset, len,
persistentEntity.getClass().getProtectionDomain());
@@ -1478,8 +1488,19 @@ static Method getClassLoaderMethod(PersistentEntity, ?> entity) {
ClassLoader classLoader = entity.getType().getClassLoader();
Class> classLoaderClass = classLoader.getClass();
- return ReflectionUtils.findMethod(classLoaderClass, "defineClass", String.class, byte[].class, Integer.TYPE,
- Integer.TYPE, ProtectionDomain.class);
+ Method defineClass = ReflectionUtils.findMethod( //
+ classLoaderClass, //
+ "defineClass", //
+ String.class, //
+ byte[].class, //
+ Integer.TYPE, //
+ Integer.TYPE, //
+ ProtectionDomain.class //
+ );
+
+ defineClass.setAccessible(true);
+
+ return defineClass;
}
}
}