harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pavel Pervov" <pmcfi...@gmail.com>
Subject Re: About the loading constraint
Date Fri, 14 Dec 2007 10:56:10 GMT
Xiaobing,

this is interesting observation indeed and it certainly deserves JIRA.

Could you, please, file a JIRA and provide the whole test case and citation
(or link) to the spec where this behaviour is defined?

Thank you very much.


On 12/14/07, Xiaobing Wong <litleicew@gmail.com> wrote:
>
> Loading constraint is a new regulation since sun jdk 1.2.I use a test
> suit,
> finding that there are some difference between harmony and sun jdk 1.5about
> the loading constraint. And I am not quite sure about the native
> resolution
> of harmony. Who can help me to explain why???
>
>
>
> There are two Spoofed.class. One is under the current direction, the other
> is under the direction : greeters/ . They are different but with the same
> name.
>
> Spoofed.class
>
> public class Spoofed {
>
>    private int secretValue = 42;
>
>    public int giveMeFive() {
>
>        return 5;
>
>    }
>
>    static {
>
>        System.out.println(
>
>            "linking/ex8/Spoofed initialized.");
>
>    }
>
> }
>
> greeters/Spoofed.class
>
> public class Spoofed {
>
>    private int secretValue = 100;
>
>    public int giveMeFive() {
>
>        return secretValue;
>
>    }
>
>    static {
>
>        System.out.println(
>
>            "linking/ex8/greeters/Spoofed initialized.");
>
>    }
>
> }
>
>
>
> The method to invoke loading is as followed:
>
>    public void greet() {
>
>        Spoofed spoofed = new Spoofed();
>
>        System.out.println("secret val = "+ spoofed.giveMeFive());
>
>        spoofed = Delegated.getSpoofed();
>
>        System.out.println("secret val = "+ spoofed.giveMeFive());
>
>    }
>
> In which the Delegated.class:
>
> public class Delegated {
>
>    public static Spoofed getSpoofed() {
>
>        return new Spoofed();
>
>    }
>
> }
>
>
>
> Then we define the classloader to load the Spoofed.class in greeters. The
> main function invokes greet().Results show as follows:
>
>
>
> Result In sun jdk 1.5:
>
> D:\linking\ex8>java Greet greeters Cracker
>
> linking/ex8/greeters/Spoofed initialized.
>
> secret val = 100
>
> Exception in thread "main" java.lang.LinkageError: Class Spoofed violates
> loader
>
> constraints
>
>        at java.lang.ClassLoader.defineClass1(Native Method)
>
>        at java.lang.ClassLoader.defineClass(Unknown Source)
>
>        at java.security.SecureClassLoader.defineClass(Unknown Source)
>
>        at java.net.URLClassLoader.defineClass(Unknown Source)
>
>        at java.net.URLClassLoader.access$100(Unknown Source)
>
>        at java.net.URLClassLoader$1.run(Unknown Source)
>
>        at java.security.AccessController.doPrivileged(Native Method)
>
>        at java.net.URLClassLoader.findClass(Unknown Source)
>
>        at java.lang.ClassLoader.loadClass(Unknown Source)
>
>        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
>
>        at java.lang.ClassLoader.loadClass(Unknown Source)
>
>        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
>
>        at Delegated.getSpoofed(Delegated.java:7)
>
>        at Cracker.greet(Cracker.java:13)
>
>        at Greet.main(Greet.java:39)
>
>
>
> Result In harmony:
>
> littleice@littleice-desktop:/trunk/target/hdk/jdk/jre/bin$ ./java Greet
> greeters Cracker
>
> linking/ex8/greeters/Spoofed initialized.
>
> secret val = 100
>
> linking/ex8/Spoofed initialized.
>
> secret val = 5
>
> littleice@littleice-desktop:/trunk/target/hdk/jdk/jre/bin$
>



-- 
Pavel Pervov,
Intel Enterprise Solutions Software Division

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message