[Biojava-l] serializing a SimpleSequence? "NoSuchFieldException: DEFAULT"

Paul Shannon pshannon@systemsbiology.org
Tue, 9 Jul 2002 16:38:58 -0700


I'd like to write a org.biojava.bio.seq.Sequence to an RMI server, for which
of course it needs to be serializable.  After first encountering
difficulty, I removed the RMI code, replacing it with a couple of lines
that try to write fasta sequences, serialized, to a file.  The same
exception happens there.



    BufferedReader br = new BufferedReader (new FileReader (fileName));
    SequenceIterator seqIter = SeqIOTools.readFastaDNA (br);

    FileOutputStream out = new FileOutputStream ("seq.bin");
    ObjectOutputStream s = new ObjectOutputStream (out);

    while (seqIter.hasNext()) {
      Sequence seq = seqIter.nextSequence ();
      s.writeObject (seq);                           // line 27
      }




The full text of the exception:

Exception in thread "main" java.lang.NoSuchFieldException: DEFAULT
	at java.lang.Class.getField0(Class.java:1721)
	at java.lang.Class.getField(Class.java:889)
	at org.biojava.bio.seq.impl.FeatureImpl$1.writeReplace(FeatureImpl.java:57)
            rethrown as org.biojava.bio.BioError
	at org.biojava.bio.seq.impl.FeatureImpl$1.writeReplace(FeatureImpl.java:59)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at java.io.ObjectStreamClass.invokeWriteReplace(ObjectStreamClass.java:867)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1011)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1330)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1302)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1245)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
	at go.main(go.java:27)

I admit to being quite confused about how and when concrete classes are created for
interfaces.  I see that seqIter.nextSequence () actually returns a SimpleSequence
in the while loop above, but I do not know when and how that choice is made.  
I guess that is not at issue here.

Instead, the problem may have something to do with this line in the
first SimpleSequence constructor:

	this.featureRealizer = FeatureImpl.DEFAULT;

but that's just a guess.

Can anyone help me out here?  

Many thanks!

 - Paul Shannon