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)


On Wed, Dec 23, 2009 at 3:58 PM, Erik J Groeneveld <erik@cq2.nl> wrote:

> You refer to this I assume:
> "A member (class, interface, field, or method) of a reference (class,
> interface, or array) type or a constructor of a class type is accessible
> only if the type is accessible and the member or constructor is declared to
> permit access:
>
> If the member or constructor is declared?public, then access is permitted.
> All members of interfaces are implicitly?public.
> Otherwise, if the member or constructor is declared?protected, then access
> is permitted only when one of the following is true:
>
> Access to the member or constructor occurs from within the package
> containing the class in which the?protected?member or constructor is
> declared.
> Access is correct as described in?§6.6.2.
>
> Otherwise, if the member or constructor is declared?private, then access is
> permitted if and only if it occurs within the body of the top level
> class?(§7.6)?that encloses the declaration of the member or constructor.
> Otherwise, we say there is default access, which is permitted only when the
> access occurs from within the package in which the type is declared.
>
> "
> It seems that the type is accessible (Iterator) and the method is declared
> public. Then it is accessible without further conditions.
> The patch in invoke falls back to the scenario under the last bullet, which
> is not correct I believe.

In your example, you aren't testing the accessibility of Iterator, but
rather that of the class which is returned by ArrayList.iterator(),
which is indeed a package-private class from a different package!

Another fix for your code would be to change:

   java::lang::reflect::Method* m = i->getClass()->getDeclaredMethod(
           JvNewStringUTF("hasNext"), NULL);

to something like:

   java::lang::reflect::Method* m =
&(java::util::Iterator::class$)->getDeclaredMethod(
              JvNewStringUTF("hasNext"), NULL);

Bryce


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