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

Useless exception message when annotations can't be parsed [SPR-12507] #17112

spring-projects-issues opened this issue Dec 4, 2014 · 2 comments
in: core status: duplicate


Copy link

@spring-projects-issues spring-projects-issues commented Dec 4, 2014

Aaron Digulla opened SPR-12507 and commented

When a class is missing while parsing annotations in StandardAnnotationMetadata.isAnnotated, you get this exception:

java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at sun.reflect.annotation.AnnotationParser.parseClassArray(
	at sun.reflect.annotation.AnnotationParser.parseArray(
	at sun.reflect.annotation.AnnotationParser.parseMemberValue(
	at sun.reflect.annotation.AnnotationParser.parseAnnotation(
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(
	at java.lang.Class.initAnnotationsIfNecessary(
	at java.lang.Class.getAnnotations(
	at org.springframework.core.type.StandardAnnotationMetadata.isAnnotated(

The error means that Java couldn't find a class inside of annotation which has a Class value.

Can you please wrap all exceptions thrown by Class.getAnnotations() with the name of the class which you tried to parse? That would help to narrow down the problem.

Affects: 3.2.10

Issue Links:

  • #15074 java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy exception when annotation config not found needs to specify what class is not found ("duplicates")
  • #16493 AnnotationUtils.findAnnotation fails with poor diagnostics if it encounters an Annotation that references an unloadable class
  • #16995 Improve diagnostics when AnnotationAttributesReadingVisitor triggers an ArrayStoreException from Class.getAnnotations()
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 4, 2014

Aaron Digulla commented

As a workaround, copy the source for StandardAnnotationMetadata into your project and replace public boolean isAnnotated(String annotationType) with this code:

public boolean isAnnotated(String annotationType) {
    Class introspectedClass = getIntrospectedClass();
    try {
        Annotation[] anns = introspectedClass.getAnnotations();
        for (Annotation ann : anns) {
            if (ann.annotationType().getName().equals(annotationType)) {
                return true;
            for (Annotation metaAnn : ann.annotationType().getAnnotations()) {
                if (metaAnn.annotationType().getName().equals(annotationType)) {
                    return true;
    } catch( RuntimeException e ) {
        throw new RuntimeException( "Error parsing annotations of " + introspectedClass, e );
    return false;

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 4, 2014

Juergen Hoeller commented

Note that this has been fixed in the 4.0.x line and therefore also in 4.1.x already, as of 4.0.3 back in March. In more recent releases, there has been further fine-tuning in that respect since quite a few other places in the framework codebase can run into that same unpleasant JVM exception.

It's unlikely that we'll backport all of these changes. I strongly recommend an upgrade to 4.0.6 at least... or right away to 4.1.3, scheduled for next week.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core status: duplicate
None yet

No branches or pull requests

2 participants