In our project, after upgrade the SpringBoot from 3.0.4 to 3.0.6 and Spring from 6.0.6 to 6.0.9, several of our tests started to fail on
Caused by: org.springframework.aop.framework.AopConfigException: Unexpected AOP exception
at app//org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:222)
at app//org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:158)
at app//org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
at app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.buildProxy(AbstractAutoProxyCreator.java:517)
at app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:464)
at app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:369)
at app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:318)
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:434)
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773)
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
... 80 more
Caused by: java.lang.ClassCastException: class our.project.RepositoryConfiguration$LiquibaseConfiguration$$SpringCGLIB$$0 cannot be cast to class org.springframework.cglib.proxy.Factory (our.project.RepositoryConfiguration$LiquibaseConfiguration$$SpringCGLIB$$0 and org.springframework.cglib.proxy.Factory are in unnamed module of loader 'app')
at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:91)
at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:213)
... 89 more
It's not bounded just to the our.project.RepositoryConfiguration$LiquibaseConfiguration. When I disable this configuration, then similar exception occurs on next configuration.
Another weird thing is that the test passes if only the single test class is called or if this class is executed first. Otherwise the ClassCastException ocurs.
We use TestNG.
Comment From: wilkinsona
I don't recall seeing an error like this before. I think the most likely cause is a change in Spring Framework or its repackaged version of CGLib but that's really just a guess as a stack trace isn't sufficient to diagnose the problem. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Comment From: konikvranik
Hi @wilkinsona , I'm sorry I can not share the code, because it is not opensource. I'm even not capable to provide sample app, because enerally everything is working. Our application runs and works. The problem is just with small amount of tests (34 of ~5000) that started to fail after this upgrade. I assured that all spring and springboot libraries have the same version:
gradle dependencies | fgrep org.springframework | cut -f2- -d- | cut -f 1,3- -d: | sed 's/[0-9.]\+ -> \([0-9.]\+\)/\1/;s/ (.)$//' | sort | uniq =>
-- org.springframework
-- org.springframework:6.0.9
-- org.springframework.boot
-- org.springframework.boot:3.0.6
-- org.springframework.data:3.0.5
-- org.springframework.ldap:3.0.3
-- org.springframework.security:6.1.0
I just don't understand why the proxy created by Spring doesn't implement the org.springframework.cglib.proxy.Factory which is expected by spring.
Comment From: konikvranik
Additionally I tried to add constraint to Spring a Spring Boot versions to be the same as for the working setup and it fails too. So the problem must be about other libraries. What could be related to this? Bytebuddy?
Comment From: wilkinsona
I don't think it will be ByteBuddy. It isn't involved with creating CGLib proxies.
Unfortunately, without some code that reproduces the problem, I don't think we'll be able to help you here. Creating proxies, and the use of CGLib to do so, is part of Spring Framework. If you are able to narrow down the problem and provide a reproducer, or describe in the detail the steps that are required to reproduce the problem, please open a Spring Framework issue.
Comment From: konikvranik
Finally. after almost of week of investigations, I managed to isolate the sinner. Solr 8.2.1 causes this issue. With Solr 8.2.0 it works with Solr 8.2.1 there is class cast exception for spring proxies.
Hard to believe that this is related.