Skip to content

ClassUtils.forName fails to load class from ContextTypeMatchClassLoader [SPR-17452] #21984

@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 5cd525a

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions