Skip to content

Reduce nested class lookups in ClassUtils #31258

Closed
@bclozel

Description

@bclozel

While working on #31213, I have noticed that Framework performs more class lookups than we thought.

For example, we need to register reflection on jakarta.inject.Inject types; even if the type is not present on the classpath at build time, the application might try to load it at runtime anyway. If the class is not present at runtime, ClassUtils#forName will try to load both jakarta.inject.Inject and jakarta.inject$Inject.

While I understand the rationale for nested classes, I think we need to consider the following proposals:

  1. This is the expected behavior, so we'll need to amend our reflection hints engine to automatically register nested class variants no matter what. This could be the best solution for our 6.0.x branch.
  2. As part of 6.1, we could consider toning things down and only attempting to resolve nested classes if the previous segment starts with a capital letter (which is more typical for a class name), like org.example.Spring.Issue -> org.example.Spring$Issue. This could also benefit most JVM applications by reducing the amount of unnecessary lookups.
  3. Eliminate nested classes entirely; I'm not sure this is the right approach as we're likely to break existing apps for no added benefit.

Any opinion @jhoeller @snicoll ?

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)theme: aotAn issue related to Ahead-of-time processingtype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions