Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct AutoConfigurationSorter for source-style nested class name #44276

Conversation

TigerZCoder
Copy link

Since the AutoConfiguration loaded by org.springframework.core.type.classreading.SimpleMetadataReaderFactory#getMetadataReader(java.lang.String) supports source-style nested class names, developers can register AutoConfiguration in this way. However, if AutoConfiguration is used as an @AutoConfigureBefore/@AutoConfigureAfter reference (class reference in the value attribute), the source-style nested class name registration will fail in the sorting operation.
The failure caused by toSort.contains(after) in org.springframework.boot.autoconfigure.AutoConfigurationSorter#doSortByAfterAnnotation method, which requires the AutoConfiguration class name from @AutoConfigureBefore/@AutoConfigureAfter attribute to be the same as in spring.factories/AutoConfiguration.imports.
This PR fixes this issue by replacing source-style nested class names with class-style nested class names before sorting. For the purpose of minimal modification, this fix is not so elegant. Maybe you can rewrite some code to fit Spring Boot's design ideas.

Signed-off-by: tigerzhao <tigerzcode@126.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 14, 2025
@wilkinsona
Copy link
Member

wilkinsona commented Feb 14, 2025

Thanks for the PR, but I'm not sure that we should do this.

In our experience, auto-configuration classes are almost always top-level classes so the distinction between a . vs a $ separator doesn't arise. For the unusual case where an auto-configuration class is a nested class, I think we would be better to clarify in the documentation that the binary name should be used. This avoids adding complexity to the sorter. It should also perform slightly better elsewhere as well – it will avoid the failed attempt to load com.example.Example.Nested followed by the successful attempt to load com.example.Example$Nested.

Let's see what the rest of the team thinks.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Feb 14, 2025
@TigerZCoder
Copy link
Author

OK. It would be nice to have explicit rules, or even better to have a lightweight detection warning to help developers fix the sorting failure.

@wilkinsona
Copy link
Member

I've opened #44298 to improve the documentation. Unfortunately, I don't think it's possible for detection to be lightweight as there's no way of us knowing for sure if a . should have been a $ without class loading.

@wilkinsona wilkinsona closed this Feb 17, 2025
@wilkinsona wilkinsona added status: superseded An issue that has been superseded by another and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants