Re: problem with class accessiblity check in invoke (natMethod.cc)

Erik Groeneveld <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
>>     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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.