You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Mohanraj Loganathan <mo...@gmail.com> on 2009/08/05 11:45:39 UTC

HDK ClassLoader behavior differs from RI

I am getting the different output with HDK and RI with the following
scenario

Step1: Compile TestInnerClass.java [1]  by including junit.jar in the
classpath.
Step2: Through reflection call the innerclass
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"

Any thougts on this.

P.S: One of the ANT unit-testcase implements this scenario due to which 4
tests are failing.

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

Thanks and Regards,
Mohan

Re: HDK ClassLoader behavior differs from RI

Posted by Pavel Pervov <pm...@gmail.com>.
The only idea that comes to my mind is that junit is somehow available
to ri vm - either as a part of jre or through class path. There are no
other options.

2009/8/5, Mohanraj Loganathan <mo...@gmail.com>:
> I am getting the different output with HDK and RI with the following
> scenario
>
> Step1: Compile TestInnerClass.java [1]  by including junit.jar in the
> classpath.
> Step2: Through reflection call the innerclass
> 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"
>
> Any thougts on this.
>
> P.S: One of the ANT unit-testcase implements this scenario due to which 4
> tests are failing.
>
> [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();
>     }
> }
>
> Thanks and Regards,
> Mohan
>

Re: HDK ClassLoader behavior differs from RI

Posted by Mohanraj Loganathan <mo...@gmail.com>.
When i looked into the code, there is a if condition which checks whether
the caller and declared classes are in same level. This is the place
reflector tries to load the enclosing class and not finds the junit class
which is a parent of enclosing class.

 class :
> \working_vm\vm\vmcore\src\kernel_classes\javasrc\java\lang\reflect\ReflectExporter.java
>  method: allowAccess()
>               // it is allways safe to access members from the class
> declared in the
>               // same top level class as the declaring class
>              if (hasSameTopLevelClass(declaringClass, callerClass)) {
>                   return true;
>               }
>

This check holds good when one innerclass member tries to access another
innerclass member. Is there any other reason why we need to do this check?

Thanks and Regards,
Mohan

On Thu, Aug 6, 2009 at 12:52 PM, Mohanraj Loganathan
<mo...@gmail.com>wrote:

> Thanks Alexy and Pavel.
>
> I created a jira for the same -->
> https://issues.apache.org/jira/browse/HARMONY-6297
>
> Thanks and Regards,
> Mohan
>
>
> On Thu, Aug 6, 2009 at 10:05 AM, Alexey Varlamov <
> alexey.v.varlamov@gmail.com> wrote:
>
>> 2009/8/5 Pavel Pervov <pm...@gmail.com>:
>> > Ah. I've misread your original post.
>> > Harmony VM attempts to load outer class on some stage of processing
>> > inner class. This is not neccessary classloading issue. It may be
>> > reflection itself.
>>
>> Looking at the stack trace, it is indeed:
>> java.lang.NoClassDefFoundError: junit/framework/TestCase
>>        [...]
>>        at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
>>        at
>> java.lang.VMClassRegistry.getEnclosingClass(VMClassRegistry.java)
>>        at java.lang.Class.getEnclosingClass(Class.java:1065)
>>        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:9)
>>        at ClassLoadTest.main(ClassLoadTest.java:13)
>>
>> It should be possible to add a workaround here, please file this issue to
>> JIRA.
>>
>> --
>> Regards,
>> Alexey
>>
>> >
>> > 2009/8/5, Mohanraj Loganathan <mo...@gmail.com>:
>> >> I am getting the different output with HDK and RI with the following
>> >> scenario
>> >>
>> >> Step1: Compile TestInnerClass.java [1]  by including junit.jar in the
>> >> classpath.
>> >> Step2: Through reflection call the innerclass
>> >> 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"
>> >>
>> >> Any thougts on this.
>> >>
>> >> P.S: One of the ANT unit-testcase implements this scenario due to which
>> 4
>> >> tests are failing.
>> >>
>> >> [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();
>> >>     }
>> >> }
>> >>
>> >> Thanks and Regards,
>> >> Mohan
>> >>
>> >
>>
>
>
>
> --
> Mohan
>



-- 
Mohan

Re: HDK ClassLoader behavior differs from RI

Posted by Mohanraj Loganathan <mo...@gmail.com>.
Thanks Alexy and Pavel.

I created a jira for the same -->
https://issues.apache.org/jira/browse/HARMONY-6297

Thanks and Regards,
Mohan

On Thu, Aug 6, 2009 at 10:05 AM, Alexey Varlamov <
alexey.v.varlamov@gmail.com> wrote:

> 2009/8/5 Pavel Pervov <pm...@gmail.com>:
> > Ah. I've misread your original post.
> > Harmony VM attempts to load outer class on some stage of processing
> > inner class. This is not neccessary classloading issue. It may be
> > reflection itself.
>
> Looking at the stack trace, it is indeed:
> java.lang.NoClassDefFoundError: junit/framework/TestCase
>        [...]
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
>        at java.lang.VMClassRegistry.getEnclosingClass(VMClassRegistry.java)
>        at java.lang.Class.getEnclosingClass(Class.java:1065)
>        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:9)
>        at ClassLoadTest.main(ClassLoadTest.java:13)
>
> It should be possible to add a workaround here, please file this issue to
> JIRA.
>
> --
> Regards,
> Alexey
>
> >
> > 2009/8/5, Mohanraj Loganathan <mo...@gmail.com>:
> >> I am getting the different output with HDK and RI with the following
> >> scenario
> >>
> >> Step1: Compile TestInnerClass.java [1]  by including junit.jar in the
> >> classpath.
> >> Step2: Through reflection call the innerclass
> >> 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"
> >>
> >> Any thougts on this.
> >>
> >> P.S: One of the ANT unit-testcase implements this scenario due to which
> 4
> >> tests are failing.
> >>
> >> [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();
> >>     }
> >> }
> >>
> >> Thanks and Regards,
> >> Mohan
> >>
> >
>



-- 
Mohan

Re: HDK ClassLoader behavior differs from RI

Posted by Alexey Varlamov <al...@gmail.com>.
2009/8/5 Pavel Pervov <pm...@gmail.com>:
> Ah. I've misread your original post.
> Harmony VM attempts to load outer class on some stage of processing
> inner class. This is not neccessary classloading issue. It may be
> reflection itself.

Looking at the stack trace, it is indeed:
java.lang.NoClassDefFoundError: junit/framework/TestCase
        [...]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
        at java.lang.VMClassRegistry.getEnclosingClass(VMClassRegistry.java)
        at java.lang.Class.getEnclosingClass(Class.java:1065)
        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:9)
        at ClassLoadTest.main(ClassLoadTest.java:13)

It should be possible to add a workaround here, please file this issue to JIRA.

--
Regards,
Alexey

>
> 2009/8/5, Mohanraj Loganathan <mo...@gmail.com>:
>> I am getting the different output with HDK and RI with the following
>> scenario
>>
>> Step1: Compile TestInnerClass.java [1]  by including junit.jar in the
>> classpath.
>> Step2: Through reflection call the innerclass
>> 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"
>>
>> Any thougts on this.
>>
>> P.S: One of the ANT unit-testcase implements this scenario due to which 4
>> tests are failing.
>>
>> [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();
>>     }
>> }
>>
>> Thanks and Regards,
>> Mohan
>>
>

Re: HDK ClassLoader behavior differs from RI

Posted by Pavel Pervov <pm...@gmail.com>.
Ah. I've misread your original post.
Harmony VM attempts to load outer class on some stage of processing
inner class. This is not neccessary classloading issue. It may be
reflection itself.

2009/8/5, Mohanraj Loganathan <mo...@gmail.com>:
> I am getting the different output with HDK and RI with the following
> scenario
>
> Step1: Compile TestInnerClass.java [1]  by including junit.jar in the
> classpath.
> Step2: Through reflection call the innerclass
> 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"
>
> Any thougts on this.
>
> P.S: One of the ANT unit-testcase implements this scenario due to which 4
> tests are failing.
>
> [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();
>     }
> }
>
> Thanks and Regards,
> Mohan
>

Re: HDK ClassLoader behavior differs from RI

Posted by Mohanraj Loganathan <mo...@gmail.com>.
I could able to get the system out when I run the testcase with "Harmony CL
+ IBM J9 VM"

So Issue is with DRLVM Classloading only.

-Mohan


On Wed, Aug 5, 2009 at 3:15 PM, Mohanraj Loganathan <mo...@gmail.com>wrote:

> I am getting the different output with HDK and RI with the following
> scenario
>
> Step1: Compile TestInnerClass.java [1]  by including junit.jar in the
> classpath.
> Step2: Through reflection call the innerclass
> 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"
>
> Any thougts on this.
>
> P.S: One of the ANT unit-testcase implements this scenario due to which 4
> tests are failing.
>
> [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();
>     }
> }
>
> Thanks and Regards,
> Mohan
>



-- 
Mohan