我正在使用 redisson 来保存我的应用程序的会话。该应用程序使用 JSF 2.3。 我试图找到 NotSerialized 异常的原因,但该应用程序仅记录 redisson 堆栈。基本上它并不指向生成子列表的代码。
我已经检查过,我的代码没有任何子列表,所以我想知道如何找到问题的根源?
这是日志:
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)
从
arrayList.subList()
返回的列表不是 Serializable
。搜索您的代码库并确保您和您正在使用的任何框架或库都没有调用该方法。
要查找,请在 IDE 中对
subList()
的 ArrayList
元素使用“查找用法”功能。希望这是您的代码,而不是您需要修补的第三方代码。
要修复,只需从结果创建一个新的可序列化列表:
... = new ArrayList<>(myList.subList());
来源:https://glassonionblog.wordpress.com/2013/10/01/collections-sublist-not-serialized/