harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey Varlamov (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-6297) [DRLVM][Reflection] Harmony tries to load outerclass while loading innerclass through reflection which is different from RI
Date Sat, 29 Aug 2009 08:55:32 GMT

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

Alexey Varlamov commented on HARMONY-6297:
------------------------------------------

Mohanraj, such fix is incorrect, it is plain wrong. I suggest you start with a regression
test, which would cover various access cases with different kinds of inner classes - static,
local etc - to ensure the fix will not break correct access checks.

As for the way to fix your problem, I guess the simplest workaround would be checking if '$'
sign is present in simple names of both classes - though I do not remember if Java Language
Specification mandates it\s presence here.
The complete fix should either rearrange the whole execution flow of the allowAccess() method
or move hasSameTopLevelClass() implementation to native, where low-level class info is available.
The latter seems to be preferable, as less error prone way.

> [DRLVM][Reflection] Harmony tries to load outerclass while loading innerclass through
reflection which is different from RI
> ---------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6297
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6297
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>    Affects Versions: 5.0M11
>         Environment: Windows XP IA32
>            Reporter: Mohanraj Loganathan
>            Priority: Minor
>         Attachments: HARMONY-6297_patch.txt
>
>
> Harmony VM attempts to load outer class while loading the innerclass. But RI does not
do the same.
> Consider the scenario below:
> Step1: Compile TestInnerClass.java [1]  by including junit.jar in the classpath.
> Step2: Through reflection call the inner class TestInnerClass$ExceptingEntryPoint  main
method (refer [2]) without including the junit.jar in the classpath
> HDK: throws NoClassDefFoundError: junit/framework/TestCase
> RI:  prints "I am printing from TestInnerClass$ExceptingEntryPoint"
> Throws Exception[3] with DRLVM+Harmony CL. 
> But J9VM + Harmony CL / RI not throws any exception
> [1] TestInnerClass .java
> {code}
> import junit.framework.TestCase;
> public class TestInnerClass extends TestCase{
>     public static class ExceptingEntryPoint {
>         public static void main(String[] argv) {
>             System.out.println("I am printing from TestInnerClass$ExceptingEntryPoint");
>         }
>     }
> }
> {code}
> [2] Testcase: ClassLoadTest.java
> {code}
> import java.lang.reflect.Method;
> public class ClassLoadTest {
>     public void callMain() throws Exception{
>         String classname = "TestInnerClass$ExceptingEntryPoint";     
>         Class target = Class.forName(classname, true, this.getClass().getClassLoader());
>         Method main = target.getMethod("main", new Class[] {String[].class});
>         main.invoke(null, (Object[])new String[] {null});
>     }
>    
>     public static void main(String[] args) throws Exception{
>         new ClassLoadTest().callMain();
>     }
> }
> {code}
> [3] Exception
> {noformat}
> Uncaught exception in main:
> java.lang.NoClassDefFoundError: junit/framework/TestCase
>         at java.lang.ClassLoader.defineClass0(ClassLoader.java)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:367)
>         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:110)
>         at java.net.URLClassLoader.access$3(URLClassLoader.java:1)
>         at java.net.URLClassLoader$URLHandler.createClass(URLClassLoader.java:263)
>         at java.net.URLClassLoader$URLFileHandler.findClass(URLClassLoader.java:565)
>         at java.net.URLClassLoader.findClassImpl(URLClassLoader.java:1216)
>         at java.net.URLClassLoader$4.run(URLClassLoader.java:901)
>         at java.net.URLClassLoader$4.run(URLClassLoader.java:1)
>         at java.security.AccessController.doPrivilegedImpl(AccessController.java:171)
>         at java.security.AccessController.doPrivileged(AccessController.java:64)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:903)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:489)
>         at java.lang.ClassLoader$SystemClassLoader.loadClass(ClassLoader.java:871)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
>         at java.lang.VMClassRegistry.getEnclosingClass(VMClassRegistry.java)
>         at java.lang.Class.getEnclosingClass(Class.java:851)
>         at java.lang.reflect.ReflectExporter.hasSameTopLevelClass(ReflectExporter.java:176)
>         at java.lang.reflect.ReflectExporter.allowAccess(ReflectExporter.java:103)
>         at java.lang.reflect.ReflectExporter.checkMemberAccess(ReflectExporter.java:86)
>         at java.lang.reflect.Method.invoke(Method.java:311)
>         at ClassLoadTest.callMain(ClassLoadTest.java:7)
>         at ClassLoadTest.main(ClassLoadTest.java:12)
> Caused by: java.lang.ClassNotFoundException: junit.framework.TestCase
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:907)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:489)
>         at java.lang.ClassLoader$SystemClassLoader.loadClass(ClassLoader.java:871)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
>         at java.lang.ClassLoader.defineClass0(ClassLoader.java)
>         ... 22 more
> {noformat}

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


Mime
View raw message