-
Notifications
You must be signed in to change notification settings - Fork 38.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for CGLIB BeanMap utility on JDK 17 #27802
Comments
public class BeanMapTest {
public static void main(String[] args) {
var livkBean = new LivkBean(1, "1");
var beanMap = BeanMap.create(livkBean);
System.out.println(beanMap);
}
}
record LivkBean(int id, String msg) {
}
Exception in thread "main" org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @233c0b17
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:525)
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108)
at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134)
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319)
at org.springframework.cglib.beans.BeanMap$Generator.create(BeanMap.java:127)
at org.springframework.cglib.beans.BeanMap.create(BeanMap.java:59)
at com.livk.spring.beanmap.BeanMapTest.main(BeanMapTest.java:16)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @233c0b17
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:494)
... 12 more
Process finished with exit code 1
|
I upgraded to 6.0.0-M1,but this problem is still not resolved `public class BeanMapTest { record Bean(int n, String msg) { }` `Exception in thread "main" org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @270421f5 Process finished with exit code 1
|
This issue seems to be pretty specifically about the
We can do this out of the box in a patched version of the standard CGLIB BeanMap class. I'll adapt this issue title accordingly. However, please note that we might also decide to drop the BeanMap utility from our repackaged CGLIB fork completely. |
I found that adding the burningwave package solved the problem maven <dependency>
<groupId>org.burningwave</groupId>
<artifactId>core</artifactId>
<version>12.41.2</version>
</dependency> code StaticComponentContainer.Modules.exportAllToAll();
User user = new User();
user.setId(0);
user.setUsername("livk");
user.setPassword("123456");
@SuppressWarnings("unchecked")
Map<String, Object> beanMap = BeanMap.create(user);
System.out.println(beanMap); Will this package be added to Spring-core? |
I am unfortunately still seeing this issue with M5 and created a new ticket with a small project to reproduce the issue: #28860 |
I put the problem in MD
The text was updated successfully, but these errors were encountered: