#21867 changed the implementation of ClassUtils#forName: classloading is implemented with Class#forName instead of Classloader#loadClass.
Since this change one of our Spring-components ("ClassA") isn't found as an autowiring candidate for an interface ("InterfaceA") anymore: Class.forName("ClassA", false, clToUse)
clToUse: (e.g.)
So Class.forName still has issues even on modern-day JVMs... what a shame, in particular since it is an important enabler on GraalVM.
Are you using load-time weaving there? That's pretty much the only reason to use ContextTypeMatchClassLoader...
I suppose we'll have to differentiate in our ClassUtils.forName implementation, only delegating to ClassUtils.forName for standard ClassLoader arrangements.
We're enforcing the use of ClassLoader.loadClass in case of a temporary ClassLoader now, as well as in case of a dynamically re-resolved class name from a SpEL expression. This will be available in the upcoming 5.1.3.BUILD-SNAPSHOT should hopefully address your regression.
With the latest build snapshot the application starts fine and the affected Spring component is correctly identified as an autowiring candidate. Thank you!
Christoph Empl opened SPR-17452 and commented
#21867 changed the implementation of
ClassUtils#forName
: classloading is implemented withClass#forName
instead ofClassloader#loadClass
.Since this change one of our Spring-components ("
ClassA
") isn't found as an autowiring candidate for an interface ("InterfaceA
") anymore:Class.forName("ClassA", false, clToUse)
clToUse: (e.g.)
Results in:
ClassA -
its classloader is another instance ofContextTypeMatchClassLoader
: (e.g.)This classloader has two loaded classes:
InterfaceA
andClassA
.In contrast,
clToUse.loadClass("ClassA")
returns the expected result:ClassA
, its classloader is the parent ofclToUse
The affected project uses openjdk 11 (11+28).
The somehow weird behaviour of
Class#forName
is already mentioned in #18631 and #7300.Affects: 5.1.1, 5.1.2
Issue Links:
Referenced from: commits 5cd525a
The text was updated successfully, but these errors were encountered: