You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Chunrong Lai (JIRA)" <ji...@apache.org> on 2009/02/24 05:38:01 UTC

[jira] Commented: (HARMONY-6077) [eut][drlvm] Class.getMethod may return method of subtype

    [ https://issues.apache.org/jira/browse/HARMONY-6077?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12676182#action_12676182 ] 

Chunrong Lai commented on HARMONY-6077:
---------------------------------------


   I investigated the issue and saw the test case gets pass if we add "public" modifier to class Z which is the declaring class of foo(). 
   Although drlvm although regards non-public Z can not be accessed, it still regards the access is safe since Class Y (the runtime class of foo()) is public, with below code segments in java\lang\reflect\ReflectExporter.java (under vmcore\src\kernel_classes)

private boolean allowAccess(Class<?> callerClass, Class<?> declaringClass, Class<?> runtimeClass, int memberModifiers) {
        if (hasSameTopLevelClass(declaringClass, callerClass))      return true;
        if (Modifier.isPrivate(memberModifiers))                                        return false;
        // check access to public members
        if (Modifier.isPublic(memberModifiers)) {
            if (allowClassAccess(declaringClass, callerClass))  return true;    //not allow access in our test case case
            // full inspection of the hierarchy 
            if (runtimeClass != declaringClass) {
                do {
                    if (allowClassAccess(runtimeClass, callerClass) || hasSameTopLevelClass(runtimeClass, callerClass))             return true;    // why drlvm can allow the invokation in the test case
                } while ((runtimeClass = runtimeClass.getSuperclass()) != declaringClass);
            }
            return  false;
        }
        ......
}

   The fix should be removing the allowClassAccess(runtimeClass, callerClass) from the "full inspection of the hierarchy " session or just removing the whole session.

> [eut][drlvm] Class.getMethod may return method of subtype 
> ----------------------------------------------------------
>
>                 Key: HARMONY-6077
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6077
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>    Affects Versions: 5.0M8
>            Reporter: Regis Xu
>             Fix For: 5.0M9
>
>
> test case:
> X.java:
> import java.lang.reflect.*;
> import p.*;
> public class X {
>     static public void main(String args[]) {
>         Y y = new Y();
>         try {
>             Method foo = Y.class.getMethod("foo", (Class[]) null);
>             y.foo();
>             foo.invoke(y, (Object[]) null);
>         } catch (NoSuchMethodException e) {
>             // ignore
>         } catch (InvocationTargetException e) {
>             // ignore
>         } catch (IllegalAccessException e) {
>             System.out.print("FAILURE: IllegalAccessException");
>         }
>     }
> }
> Y.java
> package p;
> public class Y extends Z {
>     /* empty */
> }
> Z.java
> package p;
> class Z {
>     public void foo() {
>         System.out.println("SUCCESS"); //$NON-NLS-1$
>     }
> }
> run class X, RI and classlib with IBM VME has the same output:
> SUCCESS
> FAILURE: IllegalAccessException
> while drlvm output:
> SUCCESS
> SUCCESS
> after debugging, I found foo is public void p.Z.foo()

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.