harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wang Xiaobing (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-5318) About the loading constraints
Date Mon, 17 Dec 2007 10:30:42 GMT
About the loading constraints
-----------------------------

                 Key: HARMONY-5318
                 URL: https://issues.apache.org/jira/browse/HARMONY-5318
             Project: Harmony
          Issue Type: Test
          Components: JDK
         Environment: test 1 :winXP SP2,  sun JDK1.5_12
test 2 :Ubuntu 7. 04, harmony 

 
            Reporter: Wang Xiaobing


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.5 about the loading constraint. And I am
not quite sure about the native resolution of harmony. Who can help me to explain why??? (for
all the source codes of this example, you can find them here in the book of 
"inside the java virtual machine second edition"  http://www.artima.com/insidejvm/ed2/linkmod20.html
)

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$


-- 
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