+2003-10-25 Bryce McKinlay <bryce@mckinlay.net.nz>
+
+ PR libgcj/11780:
+ * java/lang/reflect/natMethod.cc (invoke): Look up caller and perform
+ accessibility check only if target is non-public and accessible flag
+ is not set.
+ * java/lang/reflect/natField.cc (getAddr): Likewise.
+
2003-10-24 Thomas Fitzsimmons <fitzsim@redhat.com>
* gnu/java/awt/peer/gtk/GtkDialogPeer.java (handleEvent):
// have the compiler insert the caller as a hidden argument in some
// calls. However, we never implemented that, so we have to find
// the caller by hand instead.
- gnu::gcj::runtime::StackTrace *t
- = new gnu::gcj::runtime::StackTrace(7);
- try
- {
- // We want to skip all the frames on the stack from this class.
- for (int i = 1;
- !caller || caller == &java::lang::reflect::Field::class$;
- i++)
- caller = t->classAt (i);
- }
- catch (::java::lang::ArrayIndexOutOfBoundsException *e)
- {
- }
-
+
+ using namespace java::lang::reflect;
+
jfieldID fld = _Jv_FromReflectedField (field);
_Jv_ushort flags = fld->getModifiers();
- if (! field->isAccessible ()
- && ! _Jv_CheckAccess (caller, field->getDeclaringClass(), flags))
- throw new java::lang::IllegalAccessException;
+
+ // Check accessibility, if required.
+ if (! (Modifier::isPublic (flags) || field->isAccessible()))
+ {
+ gnu::gcj::runtime::StackTrace *t
+ = new gnu::gcj::runtime::StackTrace(7);
+ try
+ {
+ // We want to skip all the frames on the stack from this class.
+ for (int i = 1; !caller || caller == &Field::class$; i++)
+ caller = t->classAt (i);
+ }
+ catch (::java::lang::ArrayIndexOutOfBoundsException *e)
+ {
+ }
+
+ if (! _Jv_CheckAccess (caller, field->getDeclaringClass(), flags))
+ throw new java::lang::IllegalAccessException;
+ }
- if (flags & java::lang::reflect::Modifier::STATIC)
+ if (flags & Modifier::STATIC)
{
jclass fldClass = field->getDeclaringClass ();
JvInitClass(fldClass);
#include <java/lang/Long.h>
#include <java/lang/Float.h>
#include <java/lang/Double.h>
+#include <java/lang/IllegalAccessException.h>
#include <java/lang/IllegalArgumentException.h>
#include <java/lang/NullPointerException.h>
#include <java/lang/ArrayIndexOutOfBoundsException.h>
jobject
java::lang::reflect::Method::invoke (jobject obj, jobjectArray args)
{
+ using namespace java::lang::reflect;
+
if (parameter_types == NULL)
getType ();
-
- gnu::gcj::runtime::StackTrace *t
- = new gnu::gcj::runtime::StackTrace(4);
- Class *caller = NULL;
- try
- {
- for (int i = 1; !caller; i++)
- {
- caller = t->classAt (i);
- }
- }
- catch (::java::lang::ArrayIndexOutOfBoundsException *e)
- {
- }
-
+
jmethodID meth = _Jv_FromReflectedMethod (this);
+
jclass klass;
- if (! java::lang::reflect::Modifier::isStatic(meth->accflags))
+ if (! Modifier::isStatic(meth->accflags))
{
if (! obj)
throw new java::lang::NullPointerException;
klass = declaringClass;
}
- if (! isAccessible() && ! _Jv_CheckAccess(caller, klass, meth->accflags))
- throw new IllegalArgumentException;
+ // Check accessibility, if required.
+ if (! (Modifier::isPublic (meth->accflags) || this->isAccessible()))
+ {
+ gnu::gcj::runtime::StackTrace *t
+ = new gnu::gcj::runtime::StackTrace(4);
+ Class *caller = NULL;
+ try
+ {
+ for (int i = 1; !caller; i++)
+ {
+ caller = t->classAt (i);
+ }
+ }
+ catch (::java::lang::ArrayIndexOutOfBoundsException *e)
+ {
+ }
+
+ if (! _Jv_CheckAccess(caller, klass, meth->accflags))
+ throw new IllegalAccessException;
+ }
return _Jv_CallAnyMethodA (obj, return_type, meth, false,
parameter_types, args);