Skip to content

Commit 59f52a9

Browse files
schaudermp911de
authored andcommitted
DATACMNS-1079 - Disable generated property accessors if ClassLoader is encapsulated.
ClassGeneratingPropertyAccessorFactory does not work with Java 9 (encapsulated modules, without --permit-illegal-access), because making ClassLoader.defineClass accessible fails. Therefore this change moves call to setAccessible to the check that ensures availability of the method so isSupported(…) returns false. Original pull request: #224.
1 parent 07da629 commit 59f52a9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,6 @@ Class<?> defineClass(String name, byte[] bytes, int offset, int len, PersistentE
14631463
try {
14641464

14651465
Method defineClass = getClassLoaderMethod(persistentEntity);
1466-
defineClass.setAccessible(true);
14671466

14681467
return (Class<?>) defineClass.invoke(classLoader, name, bytes, offset, len,
14691468
persistentEntity.getClass().getProtectionDomain());
@@ -1478,8 +1477,19 @@ static Method getClassLoaderMethod(PersistentEntity<?, ?> entity) {
14781477
ClassLoader classLoader = entity.getType().getClassLoader();
14791478
Class<?> classLoaderClass = classLoader.getClass();
14801479

1481-
return ReflectionUtils.findMethod(classLoaderClass, "defineClass", String.class, byte[].class, Integer.TYPE,
1482-
Integer.TYPE, ProtectionDomain.class);
1480+
Method defineClass = ReflectionUtils.findMethod( //
1481+
classLoaderClass, //
1482+
"defineClass", //
1483+
String.class, //
1484+
byte[].class, //
1485+
Integer.TYPE, //
1486+
Integer.TYPE, //
1487+
ProtectionDomain.class //
1488+
);
1489+
1490+
defineClass.setAccessible(true);
1491+
1492+
return defineClass;
14831493
}
14841494
}
14851495
}

0 commit comments

Comments
 (0)