ArrayStoreException in Class#getAnnotations

Philippe Marschall kustos at gmx.net
Sun Nov 24 17:07:25 UTC 2013


Hi

The following issue was been bothering me for a while:
When you have an annotation with a value that is an array of classes 
[1] and one of those classes can't be loaded with the class loader of 
defining class of the element the annotation is defined on you get a 
ArrayStoreException (stack trace below). Personally I would expect a 
NoClassDefFoundError or something similar that tells me which class 
can't  be loaded and allows me to fix the issue. Is this the intended 
behavior?

Caused by: java.lang.ArrayStoreException: 
sun.reflect.annotation.TypeNotPresentExceptionProxy
	at 
sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
	at 
sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
	at 
sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
	at 
sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
	at 
sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
	at 
sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
	at java.lang.Class.createAnnotationData(Class.java:3384)
	at java.lang.Class.annotationData(Class.java:3373)
	at java.lang.Class.getAnnotations(Class.java:3310)

The issue seems to be that AnnotationParser#parseClassValue can return a 
TypeNotPresentExceptionProxy and AnnotationParser#parseAnnotationArray 
does not check the value before storing it into a typed array.

  [1] eg.

public @interface Sample {

     Class<?>[] value();

}

I would like to take a moment to lament the fact that you no longer 
offer fastdebug builds and no longer include sources for non-API 
classes. Things like this were much easier to debug in the good old JDK 
6 days. This is double annoying when your marketing honchos are always 
touting increased developer productivity.

Cheers
Philippe



More information about the core-libs-dev mailing list