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@xxxxxxxxxx> * 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;