This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi folks, I just stumbled over a different behaviour of how the java interpreters handle static variables in classes loaded using a self written classloader. I am using a class containing a static attribute (e.g.) public class MyStatic { static int value; } I defined my class loader that has a loadClass-Method which simply loads the class data into an array: public Class loadClass(String name) throws ClassNotFoundException { System.out.println("MyClassLoader.loadClass("+name+")"); byte[] data = ... obtain class data Class c = defineClass(name, data, 0, len); resolveClass(c); return c; } Using this class loader I load a simple class: public class Loaded { public Loaded() { System.out.println("In Loaded: Value is "+MyStatic.value); } } The following test program public class Test { public static void main(String[] args) throws Exception { MyStatic.value = 5; System.out.println("Value is "+MyStatic.value); MyClassLoader loader = new MyClassLoader(); Class cls = loader.loadClass("Loaded"); cls.newInstance(); } } produces different results when executed using "java" or "gij". ---Using Sun's java---------------------- Value is 5 MyClassLoader.loadClass(Loaded) MyClassLoader.loadClass(java.lang.Object) MyClassLoader.loadClass(java.lang.System) MyClassLoader.loadClass(java.lang.StringBuffer) MyClassLoader.loadClass(MyStatic) MyClassLoader.loadClass(java.io.PrintStream) In Loaded: Value is 0 MyClassLoader.loadClass(java.lang.Class) ---Using GNU gij-------------------------- Value is 5 MyClassLoader.loadClass(Loaded) In Loaded: Value is 5 I figured that I still don't use my ClassLoader subclass the correct way, since it should only load that classes that haven't been loaded so far and I think I better overwrite the findClass-Method. But anyway: Is the different behaviour of gij considered a bug or feature? Regards, Stefan -- ----------------------------------------------------- Stefan Prelle eMail: stefan@prelle.org ICQ : 9800462
Attachment:
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |