dtzWill/vmkit — Issue #10: Reflect.inc getDeclaredAnnotations is wrong type for OpenJDK
Author: dtzWill
Created: 2011-12-22 00:32:28+00:00
State: open
Labels: failure

OpenJDK expects annotations to be byte arrays, while GNU Classpath wants an array of objects (Object[], probably Annotation[]).

The shared code in Reflect.inc presently returns an empty Object[], which is *wrong* for OpenJDK and causes the following to throw an exception (instead of printing no annotations, which is the present behavior until the various annotation-related issues are fixed):

import java.lang.annotation.Annotation;

@Deprecated
public class AnnotationTest {
public static void main(String args[]) {
for(Annotation a : AnnotationTest.class.getAnnotations()) {
System.out.println(a);
}
for(Annotation a : AnnotationTest.class.getDeclaredAnnotations()) {
System.out.println(a);
}
}
}

=============================================================
Exception in thread "main" java.lang.annotation.AnnotationFormatError: Unexpected end of annotations.
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3093)
at java.lang.Class.getAnnotations(Class.java:3073)
at AnnotationTest.main(AnnotationTest.java:7)

Which is a fairly tame/neat error considering we're returning an object array casted to a byte array :).