Skip to content

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

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

Closed
spring-projects-issues opened this issue Dec 4, 2014 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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(AnnotationParser.java:653)
	at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:460)
	at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:286)
	at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:222)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
	at java.lang.Class.initAnnotationsIfNecessary(Class.java:3079)
	at java.lang.Class.getAnnotations(Class.java:3059)
	at org.springframework.core.type.StandardAnnotationMetadata.isAnnotated(StandardAnnotationMetadata.java:123)

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:

@spring-projects-issues
Copy link
Collaborator Author

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;
}

@spring-projects-issues
Copy link
Collaborator Author

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.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants