It appears to be a problem with DocumentFactory QNameCache.  When I serialize a document to a file and read back the object back from file after that when ever I try to add any node I am getting NullPointerException.
 
Senario:
 
Document doc = createNewDoc();  //Some document
ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("doc.ser"));
oout.writeObject(doc);
oout.close();
 
ObjectInputStream in = new ObjectInputStream(new FileInputStream("doc.ser"));
Document newDoc = (Document)in.readObject();
 
newDoc.getRootElement().addElement("TEST");  //Here I get NullPointerException.
 
The reason is in DocumentFactory.java the QNameCache cache is declared as transient.  After deserilazation the transient variables are assigned to null.  The addElement calls createQName method in which
 
cache.get(localName, namespace) // throws NullPointerException since there is not cache variable.
 
 
Solution:
 
add the following code to the DocumentFactory.java
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException
{
  in.defaultReadObject();
  cache = createQNameCache(this);
}
 
Any comments --

Kesav Kumar Kolla
Voquette Inc
650 356 3740(W)
510 889 6840(R)
Voquette - The Power of Relevant Information
Send Instant Message

 

Reply via email to