8 Replies Latest reply on Jan 27, 2014 7:33 PM by xiang yingbing

    Wildfly-8.0.0-CR1 Marshalling problem

    xiang yingbing Master

      Dear guys,

       

      I found a very interesting bug with JBoss Marshalling:

       

      Bellow ArrayList can NOT be serialized by JBoss Marshalling correctly:

       

      ArrayList<XOrder> orderbyList = new ArrayList<XOrder>(){

                  {

                      this.add(new XOrder("createDate",orderbyCreateDateAsc));

                  }

      };

      or

      ArrayList<XOrder> orderbyList = new ArrayList<XOrder>(){

          private static final long serialVersionUID = 1L;

                  {

                      this.add(new XOrder("createDate",orderbyCreateDateAsc));

                  }

      };

       

      Here, XOrder implements java.io.Serializable.

       

       

       

      If I change above codes to:

      ArrayList<XOrder> orderbyList = new ArrayList<XOrder>();

      orderbyList.add(new XOrder("createDate",orderbyCreateDateAsc));

       

      Then, JBoss Marshalling process it well.

       

       

       

      It is NOT a severe problem.

        • 1. Re: Wildfly-8.0.0-CR1 Marshalling problem
          Darren Jones Newbie

          Is it anything to do with the Serializability of the containing class? By doing this (or the second example):

           

          ArrayList<XOrder> orderbyList = new ArrayList<XOrder>(){

                      {

                          this.add(new XOrder("createDate",orderbyCreateDateAsc));

                      }

          };

           

          ... an anonymous inner class is being created, which carries around with it a reference to its containing class. If you use a static inner class instead, does it work? Something like this (please forgive syntax errors!):

           

          public class ContainingClass

          {

               private static class MyArrayList extends ArrayList<XOrder> {

                    public MyArrayList(Object orderByCreateDateAsc) {

                          this.add(new XOrder("createDate",orderbyCreateDateAsc));

                    }

               }

          }

          ...

          Then try to construct and marshall MyArrayList...

          • 2. Re: Wildfly-8.0.0-CR1 Marshalling problem
            xiang yingbing Master

            Is it anything to do with the Serializability of the containing class?

            ~~~~~At first, I did NOT believe this can happen too. But this does happen, and I spent much time to find it out.

            • 3. Re: Wildfly-8.0.0-CR1 Marshalling problem
              David Lloyd Master

              This is interesting.  What is the symptom of the failure?  Is there an exception on deserialize?

              • 4. Re: Wildfly-8.0.0-CR1 Marshalling problem
                xiang yingbing Master

                Caused by: java.io.NotSerializableException: com.ybxiang.nms.gui.platform.AlarmView

                    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:894)

                    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1066)

                    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1022)

                    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:888)

                    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1066)

                    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1022)

                    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:888)

                    at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:62)

                    at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:115)

                    at org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver.processInvocation(RemotingConnectionEJBReceiver.java:307)

                    ... 61 more

                Caused by: an exception which occurred:

                    in field this$0

                    in field orderby

                    in object com.ybxiang.jpa.query.api.XPager@179e873"

                 

                 

                 

                **************************************************************************** related classes ************************************************************************************

                **************************************************************************** related classes ************************************************************************************

                **************************************************************************** related classes ************************************************************************************

                 

                 

                import java.io.Serializable;

                import java.util.List;

                 

                public class XPager implements Serializable {

                    private static final long serialVersionUID = 1L;

                    public static final int DEFAULT_PAGESIZE = 50;//50

                    public static final int MINIMUM_PAGESIZE = 10;

                    public static final int MAXIMUM_PAGESIZE = 100;

                    public static final int MAX_PAGESIZE = 300;

                    public static final int PAGENUM_START = 1;

                 

                    public static final String CRITERIA_FLAG = "?";

                    //public final String className;//to protect DB, please specify your classname in com.ybxiang.jpa.query.impl.PagerHelper.getResult(Class, EntityManager, XPager)

                 

                    public int pageSize = DEFAULT_PAGESIZE;

                    public int pageNum = PAGENUM_START;

                 

                    public String wherePattern;//Example: ((?)AND(?)) OR (?)

                    public List<ICriteria> conditionList;//its size equals the number of "?" in wherePattern

                    //

                    public List<XOrder> orderby;

                }

                 

                 

                 

                import java.io.Serializable;

                 

                public class XOrder implements Serializable{

                    private static final long serialVersionUID = 1L;

                 

                    public final String attributeName;

                    public final boolean asc;

                    public XOrder(String attributeName,boolean asc){

                        this.attributeName = attributeName;

                        this.asc = asc;

                    }

                }

                 

                 

                public interface ICriteria {

                }

                 

                 

                 

                import java.io.Serializable;

                import java.util.ArrayList;

                import java.util.List;

                 

                public class QueryResult implements Serializable {   

                    private static final long serialVersionUID = 1L;   

                   

                    public int pageSize = XPager.DEFAULT_PAGESIZE;

                    public int pageNum = XPager.PAGENUM_START;

                 

                    public int totalRecords = 0;

                    public int totalPages = XPager.PAGENUM_START;

                   

                    @SuppressWarnings("rawtypes")

                    public List records = new ArrayList();

                }

                 

                 

                 

                **************************************************************************** related ejb************************************************************************************

                **************************************************************************** related ejb************************************************************************************

                **************************************************************************** related ejb************************************************************************************

                public interface ISecuredRemoteSession{

                    ...

                    public QueryResult queryAfn0EErc(XPager pager);

                    ...

                }

                 

                @Remote(ISecuredRemoteSession.class)

                @Stateless

                public class SecuredRemoteSession implements ISecuredRemoteSession{

                    @PersistenceContext

                    protected EntityManager em;

                    ...

                    @PermitAll()

                    public QueryResult queryAfn0EErc(XPager pager){

                        return PagerHelper.getResult(Afn0EErc.class,em, pager);

                    }

                    ...

                }

                 

                 

                **************************************************************************** related client methods************************************************************************************

                **************************************************************************** related client methods************************************************************************************

                **************************************************************************** related client methods************************************************************************************

                 

                private final XPager pager = new XPager();

                  

                    private void rebuildPager(){

                ...
                //method-1: WRONG! JBoss MARSHALLING tool can NOT serialize/de-serialize ArrayList<XOrder> orderbyList!
                /*ArrayList<XOrder> orderbyList = new ArrayList<XOrder>(){
                {
                this.add(new XOrder("createDate",orderbyCreateDateAsc));
                }
                };*/
                //method-2:
                ArrayList<XOrder> orderbyList = new ArrayList<XOrder>();
                orderbyList.add(new XOrder("createDate",orderbyCreateDateAsc));

                 

                //
                {
                pager.wherePattern = wherePattern;
                pager.conditionList = criteriaList;
                pager.orderby = orderbyList;
                }
                }

                 

                 

                 

                 

                private ISecuredRemoteSession getSessionWithSSL(){
                   return securedRemoteSessionProxy;

                    }

                   

                    public Object[] getElements(Object inputElement) {

                   QueryResult queryResult = this.getSessionWithSSL().queryAfn0EErc(pager);
                   ...

                    }

                • 5. Re: Wildfly-8.0.0-CR1 Marshalling problem
                  Darren Jones Newbie

                  So the rebuildPager() method - could you clarify what class that is declared in? And is that Seralizable?

                  • 6. Re: Wildfly-8.0.0-CR1 Marshalling problem
                    xiang yingbing Master

                    rebuildPager() is used to update XPager.

                    XPager is transfered to Wildfly8 through EJB Client.

                    I have updated above codes.

                    • 7. Re: Wildfly-8.0.0-CR1 Marshalling problem
                      Darren Jones Newbie

                      I still think the location of the rebuildPager() method is key. Let's suppose that it's something like this (i.e. you have it in the AlarmView class):

                       

                      public class AlarmView {

                         private final XPager pager = new XPager();

                       

                         private void rebuildPager() {

                             ArrayList<XOrder> orderbyList = new ArrayList<XOrder>() {

                                 {

                                     this.add(new XOrder("createDate",orderbyCreateDateAsc));

                                 };

                             pager.orderby = orderbyList;

                          }

                      }


                      The declaration "new ArrayList<XOrder>() { ... }" is not creating a plain ArrayList. Instead it is creating an anonymous inner class that is a subclass of ArrayList.


                      This anonymous inner class carries around with it a hidden reference called this$0 to the outer class, AlarmView. Therefore to be able to Serialize the anonymous inner class, the AlarmView class must also be Serializable.


                      This is likely to explain why "this$0" and "com.ybxiang.nms.gui.platform.AlarmView" appear in the stack trace you reported earlier.

                      1 of 1 people found this helpful