tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wolfgang Orthuber <>
Subject Serialization
Date Mon, 04 Oct 2010 13:10:17 GMT

my tomcat version is 5.5.17, my question concerns serialization of 
objects, below is a code section for writing and reading an object. If I 
call write immediately before read:

then all works fine, but if I use only read (on an formerly written 
file) with the same code included in another program module, I got the 
exceptions like this:
java.lang.ClassCastException: org.apache.jsp.w.w4a_jsp$1ddm2 cannot be 
cast to org.apache.jsp.w.w4b_jsp$1ddm2

in which w4a.jsp and w4b.jsp are two different modules which include the 
same code for read and write. The name of the program module is stored 
in the serialized object, but the name of the program module does not 
matter, because both modules include the same code.

Do you know a simple solution which avoids the exception?


The code section with read and write:

class dm5t implements Serializable {
     public ArrayList<ddm2>    v5;

     public dm5t () {  v5 = new ArrayList<ddm2> (); }

     public String topicpath(){return 

     public synchronized boolean write () {
         String fn=fntopics;
         boolean ok=true;
         try {
             String spath = topicpath();

             FileOutputStream    fs = new FileOutputStream (spath+fn);
             ObjectOutputStream    os = new ObjectOutputStream    (fs);
             os.writeObject (v5);
             os.close ();}
         catch (IOException e) {ok=false;} return ok;}

     public synchronized boolean    read () {
         String fn=fntopics;
         boolean ok=true;
         ArrayList<ddm2>    v5tmp=null;
         try {
             String spath = topicpath();

             FileInputStream        fs = new FileInputStream (spath+fn);
             ObjectInputStream    os = new ObjectInputStream    (fs);

             v5tmp = (ArrayList<ddm2>) os.readObject ();
             os.close ();

         } catch (IOException e) {ok=false;}
         catch (ClassNotFoundException e) {ok=false;}
         if (ok)    if (v5tmp != null) v5=v5tmp;
         return ok;}

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message