This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Method.invoke() on a non-public class from another package
- From: Andrew Haley <aph at gcc dot gnu dot org>
- To: Andrew Haley <aph at gcc dot gnu dot org>
- Cc: "Robert Lougher" <rob dot lougher at gmail dot com>, "Mark Wielaard" <mark at klomp dot org>, classpath at gnu dot org, java-patches at gcc dot gnu dot org
- Date: Wed, 11 Apr 2007 18:01:56 +0100
- Subject: Re: Method.invoke() on a non-public class from another package
- References: <1175899892.12305.55.camel@dijkstra.wildebeest.org> <1175982587.4504.37.camel@dijkstra.wildebeest.org> <1176029634.3239.0.camel@localhost.localdomain> <1176066768.4504.29.camel@dijkstra.wildebeest.org> <d58509a80704081441p7f0c6b0aqfbb14812b613cdf6@mail.gmail.com> <d58509a80704081500v23bb6688y23636b33b5d34b92@mail.gmail.com> <17945.26666.93912.441902@zebedee.pink> <d58509a80704081747r6a60fc13r37078db8710a2fca@mail.gmail.com> <d58509a80704081823j303aa772jf06b24b3382d7c38@mail.gmail.com> <17947.49382.769461.8563@zebedee.pink> <17947.52236.138258.124908@zebedee.pink>
Andrew Haley writes:
> Andrew Haley writes:
> > Robert Lougher writes:
> >
> > > Had a quick look, and in Classpath-0.93 java.util.AbstractMap contains
> > > a class BasicMapEntry which implements getValue(). BasicMapEntry is
> > > package-private. This isn't accessible outside the package.
> > >
> > > In CVS HEAD, this has changed and java.util.AbstractMap contains a
> > > class SimpleEntry which implements getValue(). SimpleEntry is public.
> > > Obviously, this is accessible...
> >
> > OK, thanks. I'm working on a gcj patch now.
>
> Done.
Eww, this doesn't work for private inner classes. We must allow
access to private classes but not package-private classes in other
packages.
Here's something better.
Andrew.
2007-04-11 Andrew Haley <aph@redhat.com>
* java/lang/reflect/natMethod.cc (Method::invoke): In invoke also
check that the method's declaring class is accessible.
Index: natMethod.cc
===================================================================
*** natMethod.cc (revision 123473)
--- natMethod.cc (working copy)
***************
*** 173,184 ****
}
// Check accessibility, if required.
! if (! (Modifier::isPublic (meth->accflags) || this->isAccessible()))
{
Class *caller = _Jv_StackTrace::GetCallingClass (&Method::class$);
if (! _Jv_CheckAccess(caller, declaringClass, meth->accflags))
throw new IllegalAccessException;
}
if (declaringClass->isInterface())
iface = declaringClass;
--- 173,202 ----
}
// Check accessibility, if required.
! if (! this->isAccessible())
! {
! if (! (Modifier::isPublic (meth->accflags)))
{
Class *caller = _Jv_StackTrace::GetCallingClass (&Method::class$);
if (! _Jv_CheckAccess(caller, declaringClass, meth->accflags))
throw new IllegalAccessException;
}
+ else
+ // Method is public, check to see if class is accessible.
+ {
+ jint flags = (declaringClass->accflags
+ & (Modifier::PUBLIC
+ | Modifier::PROTECTED
+ | Modifier::PRIVATE));
+ if (flags == 0) // i.e. class is package private
+ {
+ Class *caller = _Jv_StackTrace::GetCallingClass (&Method::class$);
+ if (! _Jv_ClassNameSamePackage (caller->name,
+ declaringClass->name))
+ throw new IllegalAccessException;
+ }
+ }
+ }
if (declaringClass->isInterface())
iface = declaringClass;