MergedAnnotationReadingVisitor should ignore types that cannot be loaded
See original GitHub issueOverview
This came up in the context of Spring Native, when the exception below was thrown.
TypeAccess
is an enum used in the org.springframework.nativex.hint.TypeHint
annotation.
@TypeHint
is declared in the user code but is not present on the classpath at runtime.
java.lang.IllegalArgumentException: Could not find class [org.springframework.nativex.hint.TypeAccess]
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:334)
at org.springframework.core.type.classreading.MergedAnnotationReadingVisitor.visitEnum(MergedAnnotationReadingVisitor.java:103)
at org.springframework.core.type.classreading.MergedAnnotationReadingVisitor$ArrayVisitor.visitEnum(MergedAnnotationReadingVisitor.java:169)
at org.springframework.asm.ClassReader.readElementValue(ClassReader.java:3081)
at org.springframework.asm.ClassReader.readElementValues(ClassReader.java:3006)
at org.springframework.asm.ClassReader.readElementValue(ClassReader.java:3180)
at org.springframework.asm.ClassReader.readElementValues(ClassReader.java:3000)
at org.springframework.asm.ClassReader.accept(ClassReader.java:610)
at org.springframework.asm.ClassReader.accept(ClassReader.java:426)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:49)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:132)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.addCandidateComponentsFromIndex(ClassPathScanningCandidateComponentProvider.java:387)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:313)
at org.springframework.boot.test.context.AnnotatedClassFinder.scanPackage(AnnotatedClassFinder.java:90)
at org.springframework.boot.test.context.AnnotatedClassFinder.findFromPackage(AnnotatedClassFinder.java:82)
at org.springframework.boot.test.context.AnnotatedClassFinder.findFromClass(AnnotatedClassFinder.java:68)
at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.getOrFindConfigurationClasses(SpringBootTestContextBootstrapper.java:235)
at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.processMergedContextConfiguration(SpringBootTestContextBootstrapper.java:152)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:392)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildDefaultMergedContextConfiguration(AbstractTestContextBootstrapper.java:309)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:262)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:107)
at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.buildTestContext(SpringBootTestContextBootstrapper.java:102)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:137)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:122)
Proposal
Introduce try-catch blocks in MergedAnnotationReadingVisitor
’s visitEnum(String, String, Consumer<E>)
and visitAnnotation(String, Consumer<MergedAnnotation<T>>)
methods, and ignore types that cannot be loaded via ClassUtils.resolveClassName(...)
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
java.lang.ClassNotFoundException: org.springframework.core ...
It looks like the MergedAnnotations are in the spring-core dependency, so if the spring-boot is not the parent then you'll need to include...
Read more >Diff - platform/tools/metalava - Google Git
Merge changes from topic "metalava-from-source" into pi-dev * changes: Compile stub-annotations.jar and dist-for-goals it. Build metalava as part of the ...
Read more >MergedAnnotations (Spring Framework 6.0.2 API)
Provides access to a collection of merged annotations, usually obtained from a source such as a Class or Method . Each merged annotation...
Read more >Index (spring-core 5.2.5.RELEASE API) - javadoc.io
The annotation visitor to which this visitor must delegate method calls. ... Read (assemble) an object of type T from the given InputStream....
Read more >BioThings SDK - BioThings.io
For any given “BioThings” type, BioThings SDK helps developers to ... ignore will skip any duplicates, only the first one found will be ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @viktorardelean,
Thanks for offering to help. Much appreciated!
However, I actually meant to assign this one to myself (which I’ve now done), since I will work on the fix and determine if it’s a regression that needs to be backported.
Update: the status quo for Spring Framework 5.1.x has been tested in https://github.com/spring-projects/spring-framework/commit/8de2a9b74dbcdc98f00074d1a0e4456b32e5bc63.