From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31179 invoked by alias); 23 Dec 2009 20:57:36 -0000 Received: (qmail 31165 invoked by uid 22791); 23 Dec 2009 20:57:36 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40 X-Spam-Check-By: sourceware.org Received: from mail-px0-f192.google.com (HELO mail-px0-f192.google.com) (209.85.216.192) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 23 Dec 2009 20:57:30 +0000 Received: by pxi30 with SMTP id 30so4948866pxi.14 for ; Wed, 23 Dec 2009 12:57:28 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.251.20 with SMTP id y20mr7133076rvh.206.1261601848521; Wed, 23 Dec 2009 12:57:28 -0800 (PST) In-Reply-To: <4B326527.6030809@redhat.com> References: <4B31F521.1010404@redhat.com> <7230133d0912230709r4aaa858du760202283165869f@mail.gmail.com> <7230133d0912230844g224bd43cm5290fcabd1f1b1ae@mail.gmail.com> <4B326527.6030809@redhat.com> Date: Wed, 23 Dec 2009 20:57:00 -0000 Message-ID: Subject: Re: problem with class accessiblity check in invoke (natMethod.cc) From: Erik Groeneveld To: Andrew Haley Cc: java Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact java-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-owner@gcc.gnu.org X-SW-Source: 2009-12/txt/msg00069.txt.bz2 >> =C2=A0 =C2=A0 java::util::ArrayList* l =3D new java::util::ArrayList(); >> =C2=A0 =C2=A0 java::util::Iterator* i =3D l->iterator(); >> =C2=A0 =C2=A0 i =3D l->iterator(); >> =C2=A0 =C2=A0 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 =3D new ArrayList(); Iterator i =3D l.iterator(); i.hasNext(); And your example indeed raises IllegalAccessException in both OpenJDK and G= CJ: > import java.lang.reflect.*; > import java.util.*; > > public class Problem > { > =C2=A0public static void main(String[] args) > =C2=A0 =C2=A0throws Throwable > =C2=A0{ > =C2=A0 =C2=A0ArrayList l =3D new ArrayList(); > =C2=A0 =C2=A0Iterator i =3D l.iterator(); > =C2=A0 =C2=A0Method m =3D (i.getClass().getDeclaredMethod > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0("hasNext", null)); > =C2=A0 =C2=A0m.invoke(i, null); > =C2=A0} > } 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