java.io.NotSerializableException: java.util.ArrayList$SubList

一个同事发MQ消息,类似代码如下


 List list = new ArrayList(200);
        for (int i = 0; i < 100; i++) {
            list.add(i);
        }
        for (int j = 0; j < 33; j++) {
            TestDto t = new TestDto();
            t.setList(list.subList(0, 3));
            p.send(t);
            list.subList(0, 3).clear();
        }
        if (!list.isEmpty()) {
            TestDto t = new TestDto();
            t.setList(list);
            p.send(t);
        }


抛出异常信息:


java.lang.RuntimeException: java.util.ArrayList$SubList
at org.apache.activemq.command.ActiveMQObjectMessage.storeContent(ActiveMQObjectMessage.java:118)
at org.apache.activemq.command.ActiveMQObjectMessage.setObject(ActiveMQObjectMessage.java:169)
at com.iboxpay.base.mq.IboxpayMessageConverter.toMessage(IboxpayMessageConverter.java:20)
at org.springframework.jms.core.JmsTemplate$5.createMessage(JmsTemplate.java:661)
at org.springframework.jms.core.JmsTemplate.doSend(JmsTemplate.java:603)
at org.springframework.jms.core.JmsTemplate$3.doInJms(JmsTemplate.java:572)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:569)
at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:658)
at com.iboxpay.base.mq.IboxpayMessageProducer.send(IboxpayMessageProducer.java:55)
at com.iboxpay.session.SessionServlet.process(SessionServlet.java:60)
at com.iboxpay.session.SessionServlet.doPost(SessionServlet.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.NotSerializableException: java.util.ArrayList$SubList
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at org.apache.activemq.command.ActiveMQObjectMessage.storeContent(ActiveMQObjectMessage.java:112)
... 33 more



GOOGLE,

http://stackoverflow.com/questions/11045850/error-jsf-primefaces-serializable-of-arraylist-doesnt-work


At some point you're using something like: x = myArrayList.subList(a,b));

After this x will not be serializable as the sublist object returned from subList() does not implement it. Try doing x = new ArrayList(myArrayList.subList(a,b))); instead.


你可能感兴趣的:(JVM,JAVA)