javajsfserializationjavabeansredisson

Find cause of NotSerializableException: java.util.ArrayList$SubList


I'm using redisson to save sessions of my app. The app uses JSF 2.3. I'm trying to find the cause of a NotSerializable Exception, but the app only logs redisson stack. Basically it doesn't point to the code that generates the sublist.

I already check and my code doesn't have any sublist, so I was wondering how can I find the origin of the problem?

This is the log:

java.io.NotSerializableException: java.util.ArrayList$SubList
            org.redisson.command.CommandAsyncService.encodeMapValue(CommandAsyncService.java:669)
                              org.redisson.RedissonObject.encodeMapValue(RedissonObject.java:351)
                                     org.redisson.RedissonMap.encodeMapKeys(RedissonMap.java:1051)
                              org.redisson.RedissonMap.putAllOperationAsync(RedissonMap.java:775)
                                       org.redisson.RedissonMap.putAllAsync(RedissonMap.java:716)
                                            org.redisson.RedissonMap.putAll(RedissonMap.java:669)
                               org.redisson.tomcat.RedissonSession.save(RedissonSession.java:428)
                org.redisson.tomcat.RedissonSessionManager.store(RedissonSessionManager.java:419)
                                     org.redisson.tomcat.UpdateValve.invoke(UpdateValve.java:74)
           org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
                    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
                    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698)
                org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
                      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:364)
                       org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:624)
                org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
          org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831)
               org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1650)
                 org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
         org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
        org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
              org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
                                                            java.lang.Thread.run(Thread.java:748)

caused by java.io.NotSerializableException: java.util.ArrayList$SubList
                             java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
                       java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
                          java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
                      java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
                             java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
                              java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
                                         java.util.HashMap.internalWriteEntries(HashMap.java:1793)
                                                  java.util.HashMap.writeObject(HashMap.java:1363)
                                sun.reflect.GeneratedMethodAccessor239.invoke(Unknown Source)
           sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                                 java.lang.reflect.Method.invoke(Method.java:498)
                          java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1155)
                          java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
                      java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
                             java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
                              java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
                             java.util.LinkedHashMap.internalWriteEntries(LinkedHashMap.java:333)
                                                  java.util.HashMap.writeObject(HashMap.java:1363)
                                sun.reflect.GeneratedMethodAccessor239.invoke(Unknown Source)
           sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                                 java.lang.reflect.Method.invoke(Method.java:498)
                          java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1155)
                          java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
                      java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
                             java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
                       java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
                       java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)
                          java.util.Collections$SynchronizedMap.writeObject(Collections.java:2693)
                                sun.reflect.GeneratedMethodAccessor355.invoke(Unknown Source)
           sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                                                 java.lang.reflect.Method.invoke(Method.java:498)
                          java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1155)
                          java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
                      java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
                             java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
                              java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
                      org.redisson.codec.SerializationCodec$2.encode(SerializationCodec.java:78)
            org.redisson.command.CommandAsyncService.encodeMapValue(CommandAsyncService.java:667)
                              org.redisson.RedissonObject.encodeMapValue(RedissonObject.java:351)
                                     org.redisson.RedissonMap.encodeMapKeys(RedissonMap.java:1051)
                              org.redisson.RedissonMap.putAllOperationAsync(RedissonMap.java:775)
                                       org.redisson.RedissonMap.putAllAsync(RedissonMap.java:716)
                                            org.redisson.RedissonMap.putAll(RedissonMap.java:669)
                               org.redisson.tomcat.RedissonSession.save(RedissonSession.java:428)
                org.redisson.tomcat.RedissonSessionManager.store(RedissonSessionManager.java:419)
                                     org.redisson.tomcat.UpdateValve.invoke(UpdateValve.java:74)
           org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
                    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
                    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698)
                org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
                      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:364)
                       org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:624)
                org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
          org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831)
               org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1650)
                 org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
         org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
        org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
              org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
                                                            java.lang.Thread.run(Thread.java:748)

Solution

  • Lists returned from arrayList.subList() are not Serializable. Search your codebase and make sure you and none of the frameworks or libaries you're using are invoking that method.

    To find, use the "find usages" function in your IDE on the subList() element of ArrayList. Hopefully it's your code and not some third party code you will have to patch.

    To fix, simply create a new serializable list from the result:

    ... = new ArrayList<>(myList.subList());

    Source: https://glassonionblog.wordpress.com/2013/10/01/collections-sublist-not-serializable/

    EDIT:

    Another way to help track down the sublist might be to take a heap dump and use Eclipse Memory Analyzer to find all instances of the RandomAccessSubList and see what objects are holding a reference to it. That'll help give you a clue to what piece of code is creating the sublist. In any case, the sublist is in an object being held by a sessionscoped or viewscoped bean.