[ https://issues.apache.org/jira/browse/HARMONY-6297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12749531#action_12749531 ] Alexey Varlamov commented on HARMONY-6297: ------------------------------------------ Possibly I should provide more information on why I consider the suggested fix incorrect. 1) Normal access control for reflection is bound by Java language access control. This is reasonable from common sense and also is established by Java API documentation (see e.g. javadocs for j.l.r.Method.invoke()). 2) Accordingly to Java Language Specification 3rd Ed, section 6.6.1: "if the member or constructor is declared private, then access is permitted if and only if it occurs within the body of the top level class (ยง7.6) that encloses the declaration of the member or constructor." Note there is no allusions to any differences between accessibility rules for all kinds of inner classes. This basically means that nested classes do have "behavioral" difference compared to top-level classes. Anyway, please prove me wrong or right by real tests. As for the '$' test, indeed JLS defines (in chapter 13, Binary compatibility) rules for constructing names of inner classes and if _binary_ name of a class does not contain '$', the class is certainly top-level one. So this simplest workaround would be a valid fix. > [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.