-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Christoph Empl opened SPR-17452 and commented
#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.)
org.springframework.context.support.ContextTypeMatchClassLoader@34d89c26
Results in: ClassA -
its classloader is another instance of ContextTypeMatchClassLoader
: (e.g.)
org.springframework.context.support.ContextTypeMatchClassLoader$ContextOverridingClassLoader@3a2db42b
This classloader has two loaded classes: InterfaceA
and ClassA
.
In contrast, clToUse.loadClass("ClassA")
returns the expected result:
ClassA
, its classloader is the parent of clToUse
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:
- ClassUtils.forName() performance [SPR-14059] #18631 ClassUtils.forName() performance
- ClassUtils could use long form of Class.forName [SPR-17333] #21867 ClassUtils could use long form of Class.forName
- Class.forName() produces different results to ClassLoader.loadClass() in certain circumstances [SPR-2611] #7300 Class.forName() produces different results to ClassLoader.loadClass() in certain circumstances
Referenced from: commits 5cd525a