The following test program throws an IllegalAccessException with gij, but works with Sun Java. ~$ gij InvokeAnnotationMethod Exception in thread "main" java.lang.IllegalAccessException at java.lang.reflect.Method.invoke(libgcj.so.90) at test.Helper.invoke(Helper.java:11) at InvokeAnnotationMethod.main(InvokeAnnotationMethod.java:11) ~$ java InvokeAnnotationMethod ~$ java -version java version "1.6.0" Java(TM) SE Runtime Environment (build 1.6.0-b105) Java HotSpot(TM) 64-Bit Server VM (build 1.6.0-b105, mixed mode) The odd thing is that if the test.Helper class below is moved up to the default package, the program works. So there seems to be some reflection bug. Report forwarded from Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466538 ------------------------- file InvokeAnnotationMethod.java ---------------- import java.lang.annotation.*; import test.Helper; public class InvokeAnnotationMethod { public static void main(String[] args) throws Exception { Annotation ann = Inner.class.getAnnotation(Ann.class); new Helper().invoke(ann); } @Retention(RetentionPolicy.RUNTIME) public @interface Ann { public int param() default 0; } @Ann public class Inner { } } ------------------------------------------------------- ------------------------- file test/Helper.java ---------------- package test; import java.lang.reflect.Method; public class Helper { public void invoke(Object a) throws Exception { Method m = a.getClass().getMethod("param", new Class[0]); m.invoke(a, new Object[0]); } }
$ gij -version java version "1.5.0" gij (GNU libgcj) version 4.3.0 20080202 (experimental) [trunk revision 132072]
BTW this bug makes TestNG fail horribly with gcj, it relies heavily on reflection with annotations of this kind.
Closing as won't fix as libgcj (and the java front-end) has been removed from the trunk.