Shocking bug in XMLEncoder? Or me being stupid

Serializing an object that contains an emtpy LinkedList works fine on a anormal PC, but in headless environment dies at runtime with this:

[code[
java.lang.UnsatisfiedLinkError: /usr/lib/j2sdk1.4-sun/jre/lib/i386/libawt.so: libXp.so.6: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1586)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1503)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.NativeLibLoader.loadLibraries(NativeLibLoader.java:38)
at sun.awt.DebugHelper.(DebugHelper.java:29)
at java.awt.Component.(Component.java:506)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at java.beans.DefaultPersistenceDelegate.class$(DefaultPersistenceDelegate.java:83)
at java.beans.DefaultPersistenceDelegate.initBean(DefaultPersistenceDelegate.java:285)
at java.beans.DefaultPersistenceDelegate.initialize(DefaultPersistenceDelegate.java:395)
at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:103)
at java.beans.Encoder.writeObject(Encoder.java:54)
at java.beans.XMLEncoder.writeObject(XMLEncoder.java:249)



Note: its trying to instantiate a Component. God knows why - I've triple checked the class and all classes it references (only one! And that in a non-bean method signature, so should be ignored. And one interface, ditto). None use any external classes or objects except for some in java.util (hashmap, linkedlist).

Any ideas? This makes no sense to me.

I can’t see why LinkedList would be the culprit, but to make sure its not, you could extend LinkedList and serialize it manually by over-riding writeObject(ObjectOutputStream out) & readObject(…).

Clearly java.awt.Component is getting loaded for some reason. Is it being used as a base-class of something? Are there references to the GUI-related ListModel somewhere?

I don’t know anything about XMLEncoder,but clearly its different to ObjectOutputStream. XMLEncoder’s source seems to write objects using gnu.java.beans.encoder.ScanEnginewriteObject(o),but that class’s source remains elusive.

The author of XMLEncoder did leave his personal email in the source if you want to try emailing him…

From http://developer.classpath.org/doc/java/beans/XMLEncoder-source.html#line.245

39: package java.beans;
40:
41: import gnu.java.beans.encoder.ScanEngine;
42:
43: import java.io.OutputStream;
44:
45: /**
46: * This class uses the {@link PersistenceDelegate} and {@link Encoder}
47: * infrastructure to generate an XML representation of the objects it
48: * serializes.
49: *
50: * @author Robert Schuster (robertschuster@fsfe.org)
51: * @since 1.4
52: */
53: public class XMLEncoder extends Encoder
54: {
55: Object owner;
56:
57: Exception exception;
58:
59: ScanEngine scanEngine;

Maybe you should test whether the same problem occurs using regular ObjectOutputStream serialization as well as with XMLEncoder.

Isn’t the code above from GNU Classpath - where as the error comes from SUN’s SDK?

Kev

AFAICT … No, and no. I spent half an hour meticulously checking that :(.

Ha! Yes, XMLEncoder has a shocking bug.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4816484

It’s one of those screwed-up-design issues :). Sob.

From the evaluation:[quote]Reproducible as described up through 1.4.2, but no longer reproducible in 1.5
xxxxx@xxxxx 2004-08-03
This bug is no longer reproducible. The most likely reason is that the Toolkit initialization has been changed to occur when AWT components are shown or packed (or addNotify() is called). For this reason, I will be closing this bug as not reproducible.
[/quote]
Perhaps it’s time to move to Java 5 for that project… if it’s feasible for you.

Yeah, very very tight timeframe + this forced my hand. Just keeping fingers crossed that we don’t hit any regression issues between now and launch :).