Cache MetadataReader by class name to avoid duplicate metadata#36977
Open
LordKay-sudo wants to merge 1 commit into
Open
Cache MetadataReader by class name to avoid duplicate metadata#36977LordKay-sudo wants to merge 1 commit into
LordKay-sudo wants to merge 1 commit into
Conversation
Avoid retaining duplicate annotation metadata when the same .class file is discovered through different Resource representations during classpath scanning (for example, ClassPathResource vs file URL paths). Adds regression tests that reproduce spring-projectsgh-36737. Closes spring-projectsgh-36737 Signed-off-by: LordKay-sudo <lkandiro@gmail.com>
f92acdf to
59909d8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses duplicate metadata caching in
CachingMetadataReaderFactorywhen the same.classfile is discovered through differentResourcerepresentations during classpath scanning (e.g.ClassPathResourcewith a relative path vsUrlResourcewith a filesystem path).This matches the duplication described by @pkernevez and hypothesized by @sbrannen in gh-36737, and corresponds to issue 1 as split by @bclozel in #36737 (comment).
MetadataReader(and itsClassFileAnnotationMetadataon Java 24+) is retained per classConcurrentReferenceCachingMetadataReaderFactory(spring-boot#47687), while still delegating to the ClassFile-backed factory on Java 24+What this does NOT fix
gh-36737 reports several independent memory problems. This PR does not address:
MetadataReaderFactoryDelegate)management.metrics.use-global-registry=false; Spring Boot)Reproduction
On
main, the new tests fail:With this PR, all four tests in
CachingMetadataReaderFactoryTestspass.Test plan
./gradlew :spring-core:test --tests "org.springframework.core.type.classreading.CachingMetadataReaderFactoryTests"./gradlew :spring-core:test --tests "org.springframework.core.type.classreading.*"mainbefore applying the fixRelated to gh-36737