4 Replies Latest reply on Jun 18, 2009 8:56 AM by ivpu

    RandomAccessSubList exception

    gonorrhea
      11:22:25,181 WARN  [Component] Exception calling stateful session bean default @Remove method: hotelSearch
      java.lang.RuntimeException: org.jboss.serial.exception.SerializationException: Could not create instance of java.util.RandomAccessSubList - java.util.RandomAccessSubList



      what does this mean and what causes it?  thx.

        • 1. Re: RandomAccessSubList exception
          jkronegg

          Please post the full stack trace.

          • 2. Re: RandomAccessSubList exception
            ivpu

            Query object return unserializable RandomAccessSubList if there is set maxResults.


            If SFSB can't be activated, because is unserializable.


            Problem is in org.jboss.seam.framework.Query<T, E> class, which in method truncResultList(List<E> results) return Collection<E>.sublist()


            This method must see like this:


            protected List<E> truncResultList(List<E> results)
               {
                  Integer mr = getMaxResults();
                  if ( mr!=null && results.size() > mr )
                  {
                     return new ArrayList(results.subList(0, mr));
                  }
                  else
                  {
                     return results;
                  }
               }



            Or create own abstract class, which extends EntityQuery<E> class and override method getResultList()




            @Transactional
            @Override
            public List<E> getResultList() {
                return new ArrayList<E>(super.getResultList());
            }




            • 3. Re: RandomAccessSubList exception
              jkronegg

              The new ArrayList method is not correct because it does not match the subList contract.


              The List.subList(int,int) contract is to provide a view on the original list, not a shallow copy (see Range-View Operation section Sun's Collection tutorial). Thus, operations on the subList are in fact done on the original List.


              You can try with the following code:


              List list1 = new ArrayList();
              List list2 = list1.subList(0,0);
              System.out.println("size="+list1.size()); // size is 0
              list2.add("xxx");
              System.out.println("size="+list1.size()); // size is 1
              



              If you use the new ArrayList trick, you will get the following (notice the new ArrayList around list2):


              List list1 = new ArrayList();
              List list2 = new ArrayList(list1.subList(0,0));
              System.out.println("size="+list1.size()); // size is 0
              list2.add("xxx");
              System.out.println("size="+list1.size()); // size is 0
              



              By doing the new ArrayList trick, you will break the original behavior of org.jboss.seam.framework.Query.truncResultList(List<E> results).


              I can agree that you would probably rarely add elements to the list returned by truncResultList, but I would not change this original behavior.


              See also OpenJPA JIRA issue OPENJPA-1025 on that topic.

              • 4. Re: RandomAccessSubList exception
                ivpu

                Yes, I know about this problem.


                Is there any reason how to get serializable sublist?