From: Ito Kazumitsu <[EMAIL PROTECTED]> Date: Thu, 22 Dec 2005 11:08:15 +0900 (JST)
> The runtime access control is much simpler than the compile-time > access control. And we may be able to omit the checking of nested > relations of classes at runtime. Simply omitting the checking of nested relations of classes causes IllegalAccessError, which was reported in November, 2003. I am afraid Sun's VM spec: > A class or interface C is accessible to a class or interface D if and only if > either of the following conditions are true: > > (Runtime): > - C is public. > - C and D are members of the same runtime package. is incomplete and something should be said about the case where C is protected. Attached below is my proposed patch. I have deleted the checking of outer classes for determining slot_acc, but kept such checking for determining class_acc. With this patch applied, - All the regression tests pass. - Mauve test gnu.testlet.java.lang.Class.newInstance shows the same results as Sun's JDK. - The testcase attached to http://www.kaffe.org/pipermail/kaffe/2003-November/096187.html passes. --- kaffe/kaffevm/access.c.orig Thu Dec 22 08:45:13 2005 +++ kaffe/kaffevm/access.c Thu Dec 22 14:42:08 2005 @@ -153,45 +153,6 @@ } } -/* - * Returns 1 if oc is an outer class of c - */ -static -int outerof (Hjava_lang_Class *c, Hjava_lang_Class *oc) -{ - innerClass *ic; - Hjava_lang_Class *outer; - errorInfo einfo; - - outer = NULL; - if( c->this_inner_index >= 0 ) - { - ic = &c->inner_classes[c->this_inner_index]; - if( ic->outer_class ) - { - outer = getClass(ic->outer_class, c, &einfo); - if( outer == NULL ) - { - discardErrorInfo(&einfo); - } - } - } - if ( outer != NULL ) - { - if ( oc == outer) - { - return 1; - } - else - { - return outerof(outer, oc); - } - } - else { - return 0; - } -} - int checkAccess(struct Hjava_lang_Class *context, struct Hjava_lang_Class *target, accessFlags target_flags) @@ -209,20 +170,15 @@ return 1; } - else if ( outerof(target, context) ) - { - /* target is within the context. */ - class_acc = 1; - slot_acc = 1; - - return 1; - } else if( target->accflags & ACC_PUBLIC ) { /* Public class. */ class_acc = 1; } - else if( instanceof(target, context) ) + /* Sun's VM spec does not refer to the case where the target class + * is protected. + */ + else if( target->accflags & ACC_PROTECTED && instanceof(target, context) ) { class_acc = 1; } @@ -310,51 +266,6 @@ /* Package. */ slot_acc = 1; } -/* - Commented out because private members get accessible to - any context in the same package if target is a nested class. - - else if( (target->name->data[0] != '[') && - same_package && - (target->this_inner_index >= 0) ) - { - slot_acc = 1; - } -*/ - else if( context->this_inner_index >= 0 ) - { - innerClass *ic; - - /* - * Check for an inner class accessing something in the outer. - */ - ic = &context->inner_classes[context->this_inner_index]; - if( ic->outer_class ) - { - Hjava_lang_Class *outer; - errorInfo einfo; - - outer = getClass(ic->outer_class, context, &einfo); - if( outer != NULL ) - { - if( (target_flags & ACC_PRIVATE) && - (target == outer) ) - { - /* XXX Not sure about this. */ - slot_acc = 1; - } - else if( (target_flags & ACC_PROTECTED) && - instanceof(target, outer) ) - { - slot_acc = 1; - } - } - else - { - discardErrorInfo(&einfo); - } - } - } return( class_acc && slot_acc ); } _______________________________________________ kaffe mailing list kaffe@kaffe.org http://kaffe.org/cgi-bin/mailman/listinfo/kaffe