Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-6297

[DRLVM][Reflection] Harmony tries to load outerclass while loading innerclass through reflection which is different from RI

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 5.0M11
    • None
    • DRLVM
    • None
    • Windows XP IA32

    Description

      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

      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");
              }
          }
      }
      

      [2] Testcase: ClassLoadTest.java

      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();
          }
      }
      

      [3] Exception

      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
      

      Attachments

        1. HARMONY-6297_patch.txt
          0.7 kB
          Mohanraj Loganathan
        2. harmony-6297-tests.zip
          7 kB
          Mohanraj Loganathan

        Activity

          People

            Unassigned Unassigned
            mohlogan Mohanraj Loganathan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: