-
Bug
-
Resolution: Fixed
-
P2
-
5.0
-
b66
-
x86
-
windows_xp
-
Not verified
A DESCRIPTION OF THE REQUEST :
XMLEncoder is NOT able to save an object using an Expression if the object has been loaded using another class loader.
XMLDecoder allows to give a ClassLoader to instantiate objects. But XMLEncoder does NOT allow to give a ClassLoader. This lead to ClassNotFoundException if the class to encode has been loaded by another class loader than the default class loader.
java.lang.ClassNotFoundException: package.package.ClassNameLoadedWithAnotherClassLoader
java.lang.Exception: XMLEncoder: discarding statement XMLEncoder.writeObject(ClassNameLoadedWithAnotherClassLoader);
XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener, ClassLoader cl)
JUSTIFICATION :
It does not make sense to have the ability to provide a class loader ONLY for the XMLDecoder and not for the XMLEncoder especially because XMLEncoder behaves in such a way that it performs class.forName() using the default class loader instead of the class loader of the object that it wants create.
Without a custom class loader, usage of XMLEncoder is prohibited in all applications like Ant/Tools which use their own class loader. XMLEncoder is extremely useful. Please consider this request and improving it!
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A way to provide a ClassLoader to the XMLEncoder so that it is used in the Expression/Statement class when using class.forName().newInstance.
Suggested ways:
Either an additional constructor for XMLEncoder like this:
XMLEncoder(OutputStream out, ClassLoader cl)
Or an additional method
setClassLoader(ClassLoader cl)
ACTUAL -
java.lang.ClassNotFoundException: jg.j2me.builder.gui.tests.TestFiltersModel
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at com.sun.beans.ObjectHandler.classForName(ObjectHandler.java:67)
at com.sun.beans.ObjectHandler.classForName(ObjectHandler.java:54)
at java.beans.Statement.invoke(Statement.java:140)
at java.beans.Expression.getValue(Expression.java:98)
at java.beans.Encoder.getValue(Encoder.java:85)
at java.beans.Encoder.get(Encoder.java:180)
at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:94)
at java.beans.Encoder.writeObject(Encoder.java:54)
at java.beans.XMLEncoder.writeObject(XMLEncoder.java:254)
at java.beans.Encoder.writeExpression(Encoder.java:259)
at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:369)
at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:97)
at java.beans.Encoder.writeObject(Encoder.java:54)
at java.beans.XMLEncoder.writeObject(XMLEncoder.java:254)
at java.beans.Encoder.writeObject1(Encoder.java:186)
at java.beans.Encoder.cloneStatement(Encoder.java:194)
at java.beans.Encoder.writeExpression(Encoder.java:258)
at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:369)
at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:97)
at java.beans.Encoder.writeObject(Encoder.java:54)
at java.beans.XMLEncoder.writeObject(XMLEncoder.java:254)
at java.beans.Encoder.writeObject1(Encoder.java:186)
at java.beans.Encoder.cloneStatement(Encoder.java:199)
at java.beans.Encoder.writeStatement(Encoder.java:230)
at java.beans.XMLEncoder.writeStatement(XMLEncoder.java:328)
at java.beans.XMLEncoder.writeObject(XMLEncoder.java:257)
---------- BEGIN SOURCE ----------
Too complex to provide, excepted by mail
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
No known workaround...
XMLEncoder is NOT able to save an object using an Expression if the object has been loaded using another class loader.
XMLDecoder allows to give a ClassLoader to instantiate objects. But XMLEncoder does NOT allow to give a ClassLoader. This lead to ClassNotFoundException if the class to encode has been loaded by another class loader than the default class loader.
java.lang.ClassNotFoundException: package.package.ClassNameLoadedWithAnotherClassLoader
java.lang.Exception: XMLEncoder: discarding statement XMLEncoder.writeObject(ClassNameLoadedWithAnotherClassLoader);
XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener, ClassLoader cl)
JUSTIFICATION :
It does not make sense to have the ability to provide a class loader ONLY for the XMLDecoder and not for the XMLEncoder especially because XMLEncoder behaves in such a way that it performs class.forName() using the default class loader instead of the class loader of the object that it wants create.
Without a custom class loader, usage of XMLEncoder is prohibited in all applications like Ant/Tools which use their own class loader. XMLEncoder is extremely useful. Please consider this request and improving it!
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A way to provide a ClassLoader to the XMLEncoder so that it is used in the Expression/Statement class when using class.forName().newInstance.
Suggested ways:
Either an additional constructor for XMLEncoder like this:
XMLEncoder(OutputStream out, ClassLoader cl)
Or an additional method
setClassLoader(ClassLoader cl)
ACTUAL -
java.lang.ClassNotFoundException: jg.j2me.builder.gui.tests.TestFiltersModel
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at com.sun.beans.ObjectHandler.classForName(ObjectHandler.java:67)
at com.sun.beans.ObjectHandler.classForName(ObjectHandler.java:54)
at java.beans.Statement.invoke(Statement.java:140)
at java.beans.Expression.getValue(Expression.java:98)
at java.beans.Encoder.getValue(Encoder.java:85)
at java.beans.Encoder.get(Encoder.java:180)
at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:94)
at java.beans.Encoder.writeObject(Encoder.java:54)
at java.beans.XMLEncoder.writeObject(XMLEncoder.java:254)
at java.beans.Encoder.writeExpression(Encoder.java:259)
at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:369)
at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:97)
at java.beans.Encoder.writeObject(Encoder.java:54)
at java.beans.XMLEncoder.writeObject(XMLEncoder.java:254)
at java.beans.Encoder.writeObject1(Encoder.java:186)
at java.beans.Encoder.cloneStatement(Encoder.java:194)
at java.beans.Encoder.writeExpression(Encoder.java:258)
at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:369)
at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:97)
at java.beans.Encoder.writeObject(Encoder.java:54)
at java.beans.XMLEncoder.writeObject(XMLEncoder.java:254)
at java.beans.Encoder.writeObject1(Encoder.java:186)
at java.beans.Encoder.cloneStatement(Encoder.java:199)
at java.beans.Encoder.writeStatement(Encoder.java:230)
at java.beans.XMLEncoder.writeStatement(XMLEncoder.java:328)
at java.beans.XMLEncoder.writeObject(XMLEncoder.java:257)
---------- BEGIN SOURCE ----------
Too complex to provide, excepted by mail
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
No known workaround...