This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]