Skip to content

Springboot 3.4.5 gives CGLIB errors failing existing applications which worked under version 3.4.4 #45391

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

Closed
dulshand opened this issue May 7, 2025 · 8 comments
Labels
for: external-project For an external project and not something we can fix status: duplicate A duplicate of another issue

Comments

@dulshand
Copy link

dulshand commented May 7, 2025

I am trying to upgrade a spring boot application from spring boot version 3.4.4 to 3.4.5.
Java version used is
java version "17.0.8" 2023-07-18 LTS
Java(TM) SE Runtime Environment (build 17.0.8+9-LTS-211)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.8+9-LTS-211, mixed mode, sharing)

The applications have beans with generated getters , setters and constructors using lombok version 1.18.22.
These beans are supposed to initialize with application context.
The application initialization fails with this error.
placing --add-opens=java.base/java.lang=ALL-UNNAMED in MAVEN_OPTS or JAVA_OPTS does not fix the issue.
This issue did not occur prior to spring boot 3.4.5

Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class <<my class name with lombok accessors and mutators appears here>>: Common causes of this problem include using a final class or a non-visible class
	at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:238) ~[spring-aop-6.2.6.jar:6.2.6]
	at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:168) ~[spring-aop-6.2.6.jar:6.2.6]
	at org.springframework.aop.framework.ProxyFactoryBean.getProxy(ProxyFactoryBean.java:362) ~[spring-aop-6.2.6.jar:6.2.6]
	at org.springframework.aop.framework.ProxyFactoryBean.getSingletonInstance(ProxyFactoryBean.java:320) ~[spring-aop-6.2.6.jar:6.2.6]
	at org.springframework.aop.framework.ProxyFactoryBean.getObject(ProxyFactoryBean.java:253) ~[spring-aop-6.2.6.jar:6.2.6]
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:186) ~[spring-beans-6.2.6.jar:6.2.6]
	... 89 common frames omitted
Caused by: org.springframework.cglib.core.ReflectUtils$2: No compatible defineClass mechanism detected: JVM should be started with --add-opens=java.base/java.lang=ALL-UNNAMED for ClassLoader.defineClass to be accessible. On the module path, you may not be able to define this CGLIB-generated class at all.
	at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:558) ~[spring-core-6.2.6.jar:6.2.6]
	at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:375) ~[spring-core-6.2.6.jar:6.2.6]
	at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:575) ~[spring-core-6.2.6.jar:6.2.6]
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.lambda$new$1(AbstractClassGenerator.java:107) ~[spring-core-6.2.6.jar:6.2.6]
	at org.springframework.cglib.core.internal.LoadingCache.lambda$createEntry$1(LoadingCache.java:52) ~[spring-core-6.2.6.jar:6.2.6]
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
	at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:57) ~[spring-core-6.2.6.jar:6.2.6]
	at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-6.2.6.jar:6.2.6]
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:129) ~[spring-core-6.2.6.jar:6.2.6]
	at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:321) ~[spring-core-6.2.6.jar:6.2.6]
	at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:562) ~[spring-core-6.2.6.jar:6.2.6]
	at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:407) ~[spring-core-6.2.6.jar:6.2.6]
	at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:62) ~[spring-aop-6.2.6.jar:6.2.6]
	at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:229) ~[spring-aop-6.2.6.jar:6.2.6]
	... 94 common frames omitted
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 @23c30a20
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
	at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199) ~[na:na]
	at java.base/java.lang.reflect.Method.setAccessible(Method.java:193) ~[na:na]
	at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:505) ~[spring-core-6.2.6.jar:6.2.6]
	... 107 common frames omitted
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 7, 2025
@philwebb
Copy link
Member

philwebb commented May 7, 2025

Please provide a sample application that fails with 3.4.5 but works with 3.4.4

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label May 7, 2025
@dulshand
Copy link
Author

dulshand commented May 7, 2025

Please provide a sample application that fails with 3.4.5 but works with 3.4.4

The project I am working on is proprietary.
I have a set of thread local proxy beans created in the configuration

   @Bean(destroyMethod = "destroy")
public ThreadLocalTargetSource threadLocalTenantStore() {
	ThreadLocalTargetSource result = new ThreadLocalTargetSource();
	result.setTargetBeanName("myIdStore");
	return result;
}

@Primary
@Bean(name = "proxiedThreadLocalTargetSource")
public ProxyFactoryBean proxiedThreadLocalTargetSource(ThreadLocalTargetSource threadLocalTargetSource) {
	ProxyFactoryBean result = new ProxyFactoryBean();
	result.setTargetSource(threadLocalTargetSource);
	return result;
}

@Bean(name = "myIdStore")
@Scope(scopeName = "prototype")
public PrimacyAgencyIdStore myIdStore() {
	return new MyIdStore();
}

The Bean class is similar to this

public class MyIdStore {

public String getMyId() {
	return myId;
}

public void setMyId(String myId) {
	this.myId = myId;
}

private String myId;

public void clear() {
	this.myId = null;
}

public MyIdStore(String myId) {
	this.myId = myId;
}

public MyIdStore() {

}

}

The issue happens when this bean gets created.

I was able to do a workaround like this. In my pom.xml
I had to do this:

org.springframework.boot
spring-boot-maven-plugin


--add-opens=java.base/java.lang=ALL-UNNAMED


.....

As a result it added --add-opens=java.base/java.lang=ALL-UNNAMED to the JVM options when it ran integration test. Then the integration tests did not fail.

And also when I run the application I have to add --add-opens=java.base/java.lang=ALL-UNNAMED to run the microservice.

But having to do this is not clean. Isn't it. I did not have to do that in version 3.4.4 and prior versions.

Unfortunately, I cannot load proprietary code projects to report the bug. But I am sure if you add above bean creation to any application and use spring boot 3.4.5 and run integration tests or try to start the application it will fail.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 7, 2025
@bclozel
Copy link
Member

bclozel commented May 7, 2025

We are not asking for the exact project running in production but a minimal sample that reproduces the problem.

But I am sure if you add above bean creation to any application and use spring boot 3.4.5 and run integration tests or try to start the application it will fail.

Then please do so and share it as a sample with us. If you want this to be looked at and fixed, it is way more efficient to help us reproduce the problem.

@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels May 7, 2025
@wilkinsona
Copy link
Member

I believe this is a duplicate of spring-projects/spring-framework#34824. @dulshand, please try 6.2.7-SNAPSHOT of Spring Framework that is available from https://repo.spring.io/snapshot. If that does not help, please provide the requested sample and we can re-open the issue and take another look.

@wilkinsona wilkinsona added status: duplicate A duplicate of another issue for: external-project For an external project and not something we can fix and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels May 8, 2025
@dulshand
Copy link
Author

dulshand commented May 8, 2025

I believe this is a duplicate of spring-projects/spring-framework#34824. @dulshand, please try 6.2.7-SNAPSHOT of Spring Framework that is available from https://repo.spring.io/snapshot. If that does not help, please provide the requested sample and we can re-open the issue and take another look.

Thank you for the feedback. I am using spring boot 3.4.5. Current version 3.4.5 of spring boot does not use spring framework 6.2.7-SNAPSHOT. Could you please update spring framework to 6.2.7-SNAPSHOT for spring boot 3.4.5 to use it or could you ensure that the next version of spring boot which is 3.4.6 will have spring framework 6.2.7-SNAPSHOT .

@dulshand
Copy link
Author

dulshand commented May 8, 2025

I believe this is a duplicate of spring-projects/spring-framework#34824. @dulshand, please try 6.2.7-SNAPSHOT of Spring Framework that is available from https://repo.spring.io/snapshot. If that does not help, please provide the requested sample and we can re-open the issue and take another look.

I checked the current code base for spring boot. The project properties are like this

version=3.4.6-SNAPSHOT
latestVersion=false
spring.build-type=oss

org.gradle.caching=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8

assertjVersion=3.26.3
checkstyleToolVersion=10.12.4
commonsCodecVersion=1.17.2
graalVersion=22.3
hamcrestVersion=2.2
jacksonVersion=2.18.3
javaFormatVersion=0.0.43
junitJupiterVersion=5.11.4
kotlinVersion=1.9.25
mavenVersion=3.9.4
mockitoVersion=5.14.2
nativeBuildToolsVersion=0.10.6
snakeYamlVersion=2.3
springFrameworkVersion=6.2.6
springFramework60xVersion=6.0.23
tomcatVersion=10.1.40

kotlin.stdlib.default.dependency=false

Could you kindly update springFrameworkVersion=6.2.6 to have 6.2.7 in release 3.4.6 ?

@wilkinsona
Copy link
Member

wilkinsona commented May 8, 2025

That will happen in due course. In the meantime, you can trying out 6.2.7-SNAPSHOT of Spring Framework yourself by setting the spring-framework.version property in your pom.xml or build.gradle file.

@dulshand
Copy link
Author

dulshand commented May 8, 2025

That will happen in due course. In the meantime, you can trying out 6.2.7-SNAPSHOT of Spring Framework yourself by setting the spring-framework.version property in your pom.xml or build.gradle file.

Adding <spring-framework.version>6.2.7-SNAPSHOT</spring-framework.version> to the pom.xml resolved the issue. But appreciate if it is updated properly in the springboot release in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

5 participants