This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: problem with class accessiblity check in invoke (natMethod.cc)
>> Â Â java::util::ArrayList* l = new java::util::ArrayList();
>> Â Â java::util::Iterator* i = l->iterator();
>> Â Â i = l->iterator();
>> Â Â i->hasNext();
>
> Right, because CNI is bypassing the controls.
Ok. CNI behaves just as both OpenJDK and GCJ do on corresponding Java code:
ArrayList l = new ArrayList();
Iterator i = l.iterator();
i.hasNext();
And your example indeed raises IllegalAccessException in both OpenJDK and GCJ:
> import java.lang.reflect.*;
> import java.util.*;
>
> public class Problem
> {
> Âpublic static void main(String[] args)
> Â Âthrows Throwable
> Â{
> Â ÂArrayList l = new ArrayList();
> Â ÂIterator i = l.iterator();
> Â ÂMethod m = (i.getClass().getDeclaredMethod
> Â Â Â Â Â Â Â Â("hasNext", null));
> Â Âm.invoke(i, null);
> Â}
> }
I am convinced but still unsure how to deal with it. I don't see a way
to translate the direct Java call into the corresponding reflection
part. I think I settle for the setAccessible() option.
Best regards
Erik