@@ -91,8 +91,8 @@ public PersistentPropertyAccessor getPropertyAccessor(PersistentEntity<?, ?> ent
91
91
* Checks whether an accessor class can be generated.
92
92
*
93
93
* @param entity
94
- * @return {@literal true} if the runtime is equal or greater to Java 1.7, property name hash codes are unique and the
95
- * type has a class loader we can use to re-inject types.
94
+ * @return {@literal true} if the runtime is equal or greater to Java 1.7, we can access the ClassLoader, the property
95
+ * name hash codes are unique and the type has a class loader we can use to re-inject types.
96
96
* @see PersistentPropertyAccessorFactory#isSupported(PersistentEntity)
97
97
*/
98
98
@ Override
@@ -104,6 +104,12 @@ public boolean isSupported(PersistentEntity<?, ?> entity) {
104
104
return false ;
105
105
}
106
106
107
+ try {
108
+ Evil .getClassLoaderMethod (entity );
109
+ } catch (Exception o_O ) {
110
+ return false ;
111
+ }
112
+
107
113
if (entity .getType ().getClassLoader () == null || entity .getType ().getPackage ().getName ().startsWith ("java" )) {
108
114
return false ;
109
115
}
@@ -1446,6 +1452,7 @@ public int compareTo(PropertyStackAddress o) {
1446
1452
* accessed from a class in the same class loader.
1447
1453
*
1448
1454
* @author Mark Paluch
1455
+ * @author Oliver Gierke
1449
1456
*/
1450
1457
@ UtilityClass
1451
1458
private static class Evil {
@@ -1460,25 +1467,30 @@ private static class Evil {
1460
1467
* @param persistentEntity
1461
1468
* @return
1462
1469
*/
1463
- @ SuppressWarnings ("rawtypes" )
1464
1470
Class <?> defineClass (String name , byte [] bytes , int offset , int len , PersistentEntity <?, ?> persistentEntity ) {
1465
1471
1466
1472
ClassLoader classLoader = persistentEntity .getType ().getClassLoader ();
1467
- Class <?> classLoaderClass = classLoader .getClass ();
1468
1473
1469
1474
try {
1470
1475
1471
- Class <? extends PersistentEntity > persistentEntityClass = persistentEntity .getClass ();
1472
- Method defineClass = ReflectionUtils .findMethod (classLoaderClass , "defineClass" , String .class , byte [].class ,
1473
- Integer .TYPE , Integer .TYPE , ProtectionDomain .class );
1476
+ Method defineClass = getClassLoaderMethod (persistentEntity );
1474
1477
defineClass .setAccessible (true );
1475
1478
1476
1479
return (Class <?>) defineClass .invoke (classLoader , name , bytes , offset , len ,
1477
- persistentEntityClass .getProtectionDomain ());
1480
+ persistentEntity . getClass () .getProtectionDomain ());
1478
1481
1479
1482
} catch (ReflectiveOperationException e ) {
1480
1483
throw new IllegalStateException (e );
1481
1484
}
1482
1485
}
1486
+
1487
+ static Method getClassLoaderMethod (PersistentEntity <?, ?> entity ) {
1488
+
1489
+ ClassLoader classLoader = entity .getType ().getClassLoader ();
1490
+ Class <?> classLoaderClass = classLoader .getClass ();
1491
+
1492
+ return ReflectionUtils .findMethod (classLoaderClass , "defineClass" , String .class , byte [].class , Integer .TYPE ,
1493
+ Integer .TYPE , ProtectionDomain .class );
1494
+ }
1483
1495
}
1484
1496
}
0 commit comments