question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MergedAnnotationReadingVisitor should ignore types that cannot be loaded

See original GitHub issue

Overview

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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sbrannencommented, Dec 10, 2021

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.

0reactions
sbrannencommented, Dec 14, 2021

Update: the status quo for Spring Framework 5.1.x has been tested in https://github.com/spring-projects/spring-framework/commit/8de2a9b74dbcdc98f00074d1a0e4456b32e5bc63.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found