12 Replies Latest reply on Mar 8, 2006 12:46 PM by brian.stansberry

    java.io.NotSerializableException:

    anupama

      Hi Folks,

      I have the following POJO class which needs to be apectized and has to send over wire to client.


      import java.io.Serializable;
      import java.util.ArrayList;
      
      /**
       *
       * @@org.jboss.cache.aop.AopMarker
       */
      
      public class Answer implements Serializable{
       private String itemCode;
       private String description;
       private boolean defaultItem;
       private ArrayList parentItemCodeList;
       private ArrayList amenitiesList;
       private boolean hasSuite;
       private boolean hasConcierge;
       private int maxGuest;
      
       public Answer() {
       amenitiesList = new ArrayList ();
       parentItemCodeList = new ArrayList();
       }
      
      public ArrayList getAmenitiesList() {
       return amenitiesList;
      }
      
      public void setAmenitiesList(ArrayList amenitiesList) {
       this.amenitiesList = amenitiesList;
      }
      
      public void addAmenity (String amenity){
       amenitiesList.add(amenity);
      }
      
      public boolean getDefaultItem() {
       return defaultItem;
      }
      
      public void setDefaultItem(boolean defaultItem) {
       this.defaultItem = defaultItem;
      }
      
      public String getDescription() {
       return description;
      }
      
      public void setDescription(String description) {
       this.description = description;
      }
      
      public boolean isHasConcierge() {
       return hasConcierge;
      }
      
      public void setHasConcierge(boolean hasConcierge) {
       this.hasConcierge = hasConcierge;
      }
      
      public boolean isHasSuite() {
       return hasSuite;
      }
      
      public void setHasSuite(boolean hasSuite) {
       this.hasSuite = hasSuite;
      }
      
      public String getItemCode() {
       return itemCode;
      }
      
      public void setItemCode(String itemCode) {
       this.itemCode = itemCode;
      }
      
      public int getMaxGuest() {
       return maxGuest;
      }
      
      public void setMaxGuest(int maxGuest) {
       this.maxGuest = maxGuest;
      }
      
      public ArrayList getParentItemCodeList() {
       return parentItemCodeList;
      }
      
      public void setParentItemCodeList(ArrayList parentItemCodeList) {
       this.parentItemCodeList = parentItemCodeList;
      }
      
      public void addParentItemCode(String parentItemCode){
       parentItemCodeList.add(parentItemCode);
      }
      }
      
      

      it's doing AOPC properly and even caching and retrieving it from JBoss TreeCacheAOP. it's displaying Cached contents at server properly but at client side it's giving

      java.lang.reflect.UndeclaredThrowableException
       at $Proxy1.getAnswer(Unknown Source)
       at com.wdpro.commerce.wdw.be.client.delegate.WDWIBCAppDelegate.getAnswer(WDWIBCAppDelegate.java:211)
       at TestCache.main(TestCache.java:20)
      Caused by: java.io.NotSerializableException: org.jboss.cache.aop.collection.CachedListInterceptor
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
       at java.util.ArrayList.writeObject(ArrayList.java:529)
       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.invokeWriteObject(ObjectStreamClass.java:809)
       at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1296)
       at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
       at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
       at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
       at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
       at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
       at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
       at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
       at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
       at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
       at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
       at java.rmi.MarshalledObject.<init>(MarshalledObject.java:92)
       at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:410)
       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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
       at sun.rmi.transport.Transport$1.run(Transport.java:148)
       at java.security.AccessController.doPrivileged(Native Method)
       at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
       at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
       at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
       at java.lang.Thread.run(Thread.java:534)
       at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
       at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
       at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
       at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
       at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:119)
       at org.jboss.invocation.InvokerInterceptor.invokeInvoker(InvokerInterceptor.java:227)
       at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:167)
       at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
       at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:55)
       at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:97)
       at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:86)
       ... 3 more

      when I did
      Answer ans = delegate.getAnswer()

      I don't know what I am missing here, can't cached classes accessed at client.

      Please let me know ASAP.

      Thanks alot Guys,
      Anu

        • 1. Re: java.io.NotSerializableException:
          anupama

          Hi Folks,

          one more thing to add.

          I want to cache Answer object which is structured as above but I need that to be serializable since for front-end their system won't work if objects are n't serizable.

          My question is can I make this class as seriazable and still use Tree Cache AOP. If I retrieve it from Tree Cache AOP and wrap it in other serizable object (DTO), pass DTO to client it's giving me above exception..


          What would be work around this probelm, how can I send cached object to remote client as result of getMeFromCache() delegate call.

          please reply me ASAP..

          Thanks alot,
          Anu

          • 2. Re: java.io.NotSerializableException:

            1. You don't need Anser to be Serilaizable to run TreeCacheAop.

            2. But I assume you are transporting Answer object between your client and erver? This won't work since the Answer object is "aspectized", meaning it has additonal CacheInterceptor attached (and therefore not Serializable). Serializing CacheInterceptor won't make sense anyway.

            3. I'd recommend you not to transport Answer object. Instead setup your client/server to be in the same replication group. That way, you don't need to serialze manually anyway.

            -Ben

            • 3. Re: java.io.NotSerializableException:
              anupama

              Hi Ben,

              Thanks for your reply, if I make Answer as non-serializable I need some of way of sending Answer contents in Serialized object. I don't have any control over client whatsoever, they are using TeamBridge(no Idea what it is) but it's main requirement is they need serialized object what would be best way to transport Answer Object. Moreover Answer object is very low level filed I have whole object structured as follows

              Object A will have list of Object B, Object B will have Object C and list of ObjectD, Object D have list of Object E, Object E have list of ObjectF and Object F have list of Object G (ANSWER Object). Each object have nearly 10 fields intit(String, int, ArrayList, boolean types), I need to cache ObjectA whch is heavy weighted.

              When client calls server through delegate they need Object A to pain the screen(this is the requirement), so how can I transport Object A(this is my ultimate task) which is cached to client.

              I really need your expertise help on this, I really appreciate your response.

              Thanks alot,
              Anu

              • 4. Re: java.io.NotSerializableException:

                Anu,

                What you ae looking for is the detach/re-attach capbility of which PojoCache does not have now (noy sure if it even makes sense though).

                Is the plain TreeCache an option then?

                -Ben

                • 5. Re: java.io.NotSerializableException:
                  anupama

                  hi Ben,

                  Thanks alot for your response, my question would be if we n't able to transport PoJo cached object how people are working around that. So if am n't wrong, we need to use PoJo when we need to use cached objects in middleware only.

                  I really want to take pros of PoJO cache, if that is the case I need to go for deep copy. Please let me know if there is inproper way (which takes processing/removeObject())of using PoJo cache as normal Pojo.

                  I really need to find solution for this ASAP, if there is no promising solution with POJO cache I may switch to TreeCache. since my data is read-only, at startup we will dump whole object so TreeCache will work fine for this I guess.

                  For mentioned req if I use TreeCache will I have any other known flaws.

                  Please let me know.

                  Thanks alot Ben,
                  I really appreciate ur help.

                  Anu

                  • 6. Re: java.io.NotSerializableException:

                    Usually, the use case is everyone participates in the cluster replication group as a peer. But I am not saying that it can't be done. Like I said, some form of dettach/re-attach could work. But that probably would defeat the strength of PojoCache since when detached, it won't be able to intercept the field changes. So when it is re-attached, it will have to do a putObject all over again. Not very efficient as I can see now.

                    So in this sense, you can use TreeCache to serializae/replicate the whole object. The downside is it can't handle object graph (e.g., multiple and cyclic references).

                    -Ben

                    • 7. Re: java.io.NotSerializableException:
                      brian.stansberry

                      I'm wondering if you could solve your problem by implementing read/writeObject as follows:

                      private void writeObject(java.io.ObjectOutputStream out)
                       throws IOException
                      {
                       out.writeObject(itemCode);
                       out.writeObject(description);
                       out.writeBoolean(defaultItem);
                       out.writeObject(new ArrayList(parentItemCodeList));
                       out.writeObject(new ArrayList(amenitiesList));
                       out.writeBoolean(hasSuite);
                       out.writeBoolean(hasConcierge);
                       out.writeInt(maxGuest);
                      }
                      
                      private void readObject(java.io.ObjectInputStream in)
                       throws IOException, ClassNotFoundException
                      {
                       itemCode = (String) in.readObject();
                       description = (String) in.readObject();
                       defaultItem = in.readBoolean();
                       parentItemCodeList = (ArrayList) in.readObject();
                       amenitiesList = (ArrayList) in.readObject();
                       hasSuite = in.readBoolean();
                       hasConcierge = in.readBoolean();
                       maxGuest = in.readInt();
                      }
                      


                      Your problem is the List implementation we use when the POJO is in the cache can't be serialized. The above writeObject solves this by writing a new ArrayList whose contents are the elements in the cache.

                      Note that if the objects in parentItemCodeList and amenitiesList are themselves complex objects that contain collections, the same technique would need to be used for their classes.

                      • 8. Re: java.io.NotSerializableException:

                        I think Brian's suggestion should work to explicitly define your own read/write external. If true, this is brilliant! :-)

                        • 9. Re: java.io.NotSerializableException:
                          anupama

                          Hi Brain,

                          I been caught up with something else, today I got some breathing time and
                          I tried that.
                          I am getting the following exception on client side

                          log4j:WARN No appenders could be found for logger (org.jboss.security.SecurityAssociation).
                          log4j:WARN Please initialize the log4j system properly.
                          java.lang.reflect.UndeclaredThrowableException
                           at $Proxy1.returnAnswer(Unknown Source)
                           at com.wdpro.commerce.wdw.be.client.delegate.WDWIBCAppDelegate.getAnswer(WDWIBCAppDelegate.java:213)
                           at CacheTestClient.main(CacheTestClient.java:11)
                          Caused by: java.io.IOException: unexpected exception type
                           at java.io.ObjectStreamClass.throwMiscException(ObjectStreamClass.java:1353)
                           at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:815)
                           at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1296)
                           at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
                           at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
                           at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
                           at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
                           at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
                           at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
                           at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
                           at java.rmi.MarshalledObject.<init>(MarshalledObject.java:92)
                           at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:410)
                           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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
                           at sun.rmi.transport.Transport$1.run(Transport.java:148)
                           at java.security.AccessController.doPrivileged(Native Method)
                           at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
                           at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
                           at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
                           at java.lang.Thread.run(Thread.java:534)
                           at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
                           at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
                           at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
                           at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
                           at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:119)
                           at org.jboss.invocation.InvokerInterceptor.invokeInvoker(InvokerInterceptor.java:227)
                           at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:167)
                           at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
                           at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:55)
                           at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:97)
                           at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:86)
                           ... 3 more
                          Caused by: java.lang.reflect.InvocationTargetException
                           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 org.jboss.cache.aop.collection.CollectionInterceptorUtil.invoke(CollectionInterceptorUtil.java:122)
                           at org.jboss.cache.aop.collection.CachedListInterceptor.invoke(CachedListInterceptor.java:125)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at AOPClassProxy$0.toArray(AOPClassProxy$0.java)
                           at java.util.ArrayList.<init>(ArrayList.java:136)
                           at com.wdpro.commerce.common.be.model.template.Answer.writeObject(Answer.java:76)
                           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.invokeWriteObject(ObjectStreamClass.java:809)
                           at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1296)
                           at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
                           at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
                           at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
                           at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
                           at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
                           at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
                           at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
                           at java.rmi.MarshalledObject.<init>(MarshalledObject.java:92)
                           at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:410)
                           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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
                           at sun.rmi.transport.Transport$1.run(Transport.java:148)
                           at java.security.AccessController.doPrivileged(Native Method)
                           at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
                           at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
                           at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
                           at java.lang.Thread.run(Thread.java:534)
                          Caused by: org.jboss.cache.aop.AopOperationNotSupportedException: CachedListImpl: List.toArray(a) operation not supported
                           at org.jboss.cache.aop.collection.CachedListImpl.toArray(CachedListImpl.java:125)
                           ... 36 more
                          



                          My class looks as
                          package com.wdpro.commerce.common.be.model.template;
                          
                          /**
                           *
                           * @@org.jboss.cache.aop.AopMarker
                           */
                          import java.io.IOException;
                          import java.util.ArrayList;
                          
                          import com.wdpro.commerce.common.be.model.BaseIBCModel;
                          
                          public class Answer extends BaseIBCModel {
                           private String itemCode;
                          
                           private String description;
                          
                           private boolean defaultItem;
                          
                           private ArrayList parentItemCodeList;
                          
                           // **********************TOGETHER FIELDS,DON'T CHANGE IGNORE THEM
                           /**
                           * @clientCardinality 1
                           * @supplierCardinality 1
                           * @link aggregation
                           */
                           // *******************************************************************
                          
                          
                          
                           public Answer() {
                          
                           parentItemCodeList = new ArrayList();
                           }
                          
                           public boolean getDefaultItem() {
                           return defaultItem;
                           }
                          
                           public void setDefaultItem(boolean defaultItem) {
                           this.defaultItem = defaultItem;
                           }
                          
                           public String getDescription() {
                           return description;
                           }
                          
                           public void setDescription(String description) {
                           this.description = description;
                           }
                          
                           public String getItemCode() {
                           return itemCode;
                           }
                          
                           public void setItemCode(String itemCode) {
                           this.itemCode = itemCode;
                           }
                          
                           public ArrayList getParentItemCodeList() {
                           return parentItemCodeList;
                           }
                          
                           public void setParentItemCodeList(ArrayList parentItemCodeList) {
                           this.parentItemCodeList = parentItemCodeList;
                           }
                          
                           public void setParentItemCode(String parentItemCode) {
                           parentItemCodeList.add(parentItemCode);
                           }
                          
                           private void writeObject(java.io.ObjectOutputStream out) throws IOException {
                           out.writeObject(itemCode);
                           out.writeObject(description);
                           out.writeBoolean(defaultItem);
                           out.writeObject(new ArrayList(parentItemCodeList));
                          
                           }
                          
                           private void readObject(java.io.ObjectInputStream in) throws IOException,
                           ClassNotFoundException {
                           itemCode = (String) in.readObject();
                           description = (String) in.readObject();
                           defaultItem = in.readBoolean();
                           parentItemCodeList = (ArrayList) in.readObject();
                          
                           }
                          
                          }
                          
                          


                          Do you have any idea what this means, is there anyway I can get rid of this.

                          Please let me know.
                          Anu

                          • 10. Re: java.io.NotSerializableException:
                            brian.stansberry

                            Can you try JBossCache 1.2.4.SP2? This should be fixed.

                            • 11. Re: java.io.NotSerializableException:
                              anupama

                              Hi Brain,

                              I tried with SP2, seems like it is fixed in that release. I am wondering is SP2 IS A STABLE VERSION TO USE IN PRODUCTION. Please let me know, thanks alot for your responses and are really helpful.


                              Anupama

                              • 12. Re: java.io.NotSerializableException:
                                brian.stansberry

                                Yes, 1.2.4.SP2 is a stable production release. It is the release that will be used in JBoss AS 4.0.4 when it comes out in a few weeks.