Bug 35253 - reflection on annotation objects throws IllegalAccessException
Summary: reflection on annotation objects throws IllegalAccessException
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-19 14:40 UTC by Marcus Better
Modified: 2016-09-30 22:51 UTC (History)
2 users (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Build: x86_64-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus Better 2008-02-19 14:40:37 UTC
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]);
    }
}
Comment 1 Marcus Better 2008-02-19 14:41:55 UTC
$ gij -version
java version "1.5.0"
gij (GNU libgcj) version 4.3.0 20080202 (experimental) [trunk revision 132072]
Comment 2 Marcus Better 2008-03-09 14:46:46 UTC
BTW this bug makes TestNG fail horribly with gcj, it relies heavily on reflection with annotations of this kind.
Comment 3 Andrew Pinski 2016-09-30 22:51:08 UTC
Closing as won't fix as libgcj (and the java front-end) has been removed from the trunk.