java.io.NotSerializableException 在 java 代码中?
java.io.NotSerializableException in java code?
我有 class,其中所有内部 classes 都像这样被序列化
public class BaseClass{
.......
......
.......
public class AccountPaymentDetailBean implements Serializable {
//inner class
}
}
但我的情况低于异常
java.io.NotSerializableException: com.core.shi.core.folder.BaseClass
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at org.zkoss.zk.ui.AbstractPage.writeObject(AbstractPage.java:232)
at sun.reflect.GeneratedMethodAccessor124.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601) at
java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at java.util.LinkedList.writeObject(LinkedList.java:1118) at
sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601) at
java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at
java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:438)
at
org.zkoss.zk.ui.impl.DesktopImpl.writeObject(DesktopImpl.java:1044)
at sun.reflect.GeneratedMethodAccessor118.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601) at
java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at java.util.HashMap.writeObject(HashMap.java:1100) at
sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601) at
java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at
java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:438)
at org.zkoss.util.CacheMap.writeObject(CacheMap.java:633) at
sun.reflect.GeneratedMethodAccessor112.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601) at
java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at
org.zkoss.zk.ui.http.SimpleSession.writeThis(SimpleSession.java:433)
at
org.zkoss.zk.ui.http.SerializableSession.writeObject(SerializableSession.java:71)
at sun.reflect.GeneratedMethodAccessor111.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601) at
java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at
com.csdcsystems.amanda.servlet.AmandaSessionFilter.sizeof(AmandaSessionFilter.java:88)
at
com.csdcsystems.amanda.servlet.AmandaSessionFilter.testSerializability(AmandaSessionFilter.java:73)
at
com.csdcsystems.amanda.servlet.AmandaSessionFilter.doFilter(AmandaSessionFilter.java:55)
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:501)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
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:408)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
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:722)
有人能告诉我 BaseClass$5 是什么意思吗?这个异常到底说明了什么?
Q2) 这个异常到底说明了什么?
内部 classes 不应该实现 Serializable。它们使用编译器生成的合成字段来存储对封闭实例的引用,并存储封闭范围内局部变量的值。
内部 class 的默认序列化形式定义不正确。但是,静态成员 class 可以实现 Serializable。
更多信息here.
Q1) 谁能告诉我 BaseClass$5 是什么意思?
没有更多的进一步细节。 BAseClass$5 表示这些异常发生在 class.
Q1) 谁能告诉我 BaseClass$5 是什么意思?
有时 innerclasses 没有名字。
在你的情况下它有一个名字。
我们直接即时创建一个 class(例如接口的实现者)并给出实现,并以 :) 结束它的情况。然后
class 没有名字。
那么 JVM 如何为此创建一个 .class 文件???
- 答案是 $ 命名约定。
所以这样的 classes 被创建为 BaseClass$1, BaseClass$2 ...等等。
必须至少有 5 个这样的内部未命名 classes - 检查你的 classes - 哪个得到哪个数字?-> 我认为 它纯粹是顺序。
例如- clickListener 纯属虚构,我试图展示的示例...
public class myclass{
public void mymethod(){
this.addClickListener(new ClickListener(){
public void click(){
S.O.P("Clicked !!!");
}
});
}
}
所以 CLickListener 的实现被编译为->
我的class$1.class
Could someone please tell me what is meaning of BaseClass?
BaseClass中定义的第五个匿名内部class
匿名内部 classes 被分配一个等于封闭类型的自动名称,加上一个美元符号,再加上一个序号。在您的示例中:"BaseClass" + "$" + "5".
What this exception exactly telling?
- 显然您正在使用的框架正在测试 HTTP 会话的可序列化性 (
com.csdcsystems.amanda.servlet.AmandaSessionFilter.testSerializability
)
- 并且您的会话(
org.zkoss.zk.ui.http.SerializableSession
类型)似乎在内部定义了一个匿名 BaseClass
。
- 会话中的每个对象都必须是可序列化的,因此您会收到此错误。
我有 class,其中所有内部 classes 都像这样被序列化
public class BaseClass{
.......
......
.......
public class AccountPaymentDetailBean implements Serializable {
//inner class
}
}
但我的情况低于异常
java.io.NotSerializableException: com.core.shi.core.folder.BaseClass at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346) at org.zkoss.zk.ui.AbstractPage.writeObject(AbstractPage.java:232) at sun.reflect.GeneratedMethodAccessor124.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346) at java.util.LinkedList.writeObject(LinkedList.java:1118) at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:438) at org.zkoss.zk.ui.impl.DesktopImpl.writeObject(DesktopImpl.java:1044) at sun.reflect.GeneratedMethodAccessor118.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346) at java.util.HashMap.writeObject(HashMap.java:1100) at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:438) at org.zkoss.util.CacheMap.writeObject(CacheMap.java:633) at sun.reflect.GeneratedMethodAccessor112.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346) at org.zkoss.zk.ui.http.SimpleSession.writeThis(SimpleSession.java:433) at org.zkoss.zk.ui.http.SerializableSession.writeObject(SerializableSession.java:71) at sun.reflect.GeneratedMethodAccessor111.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346) at com.csdcsystems.amanda.servlet.AmandaSessionFilter.sizeof(AmandaSessionFilter.java:88) at com.csdcsystems.amanda.servlet.AmandaSessionFilter.testSerializability(AmandaSessionFilter.java:73) at com.csdcsystems.amanda.servlet.AmandaSessionFilter.doFilter(AmandaSessionFilter.java:55) 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:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 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:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) 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:722)
有人能告诉我 BaseClass$5 是什么意思吗?这个异常到底说明了什么?
Q2) 这个异常到底说明了什么?
内部 classes 不应该实现 Serializable。它们使用编译器生成的合成字段来存储对封闭实例的引用,并存储封闭范围内局部变量的值。
内部 class 的默认序列化形式定义不正确。但是,静态成员 class 可以实现 Serializable。
更多信息here.
Q1) 谁能告诉我 BaseClass$5 是什么意思?
没有更多的进一步细节。 BAseClass$5 表示这些异常发生在 class.
Q1) 谁能告诉我 BaseClass$5 是什么意思? 有时 innerclasses 没有名字。 在你的情况下它有一个名字。 我们直接即时创建一个 class(例如接口的实现者)并给出实现,并以 :) 结束它的情况。然后 class 没有名字。 那么 JVM 如何为此创建一个 .class 文件??? - 答案是 $ 命名约定。 所以这样的 classes 被创建为 BaseClass$1, BaseClass$2 ...等等。
必须至少有 5 个这样的内部未命名 classes - 检查你的 classes - 哪个得到哪个数字?-> 我认为 它纯粹是顺序。 例如- clickListener 纯属虚构,我试图展示的示例...
public class myclass{
public void mymethod(){
this.addClickListener(new ClickListener(){
public void click(){
S.O.P("Clicked !!!");
}
});
}
}
所以 CLickListener 的实现被编译为-> 我的class$1.class
Could someone please tell me what is meaning of BaseClass?
BaseClass中定义的第五个匿名内部class
匿名内部 classes 被分配一个等于封闭类型的自动名称,加上一个美元符号,再加上一个序号。在您的示例中:"BaseClass" + "$" + "5".
What this exception exactly telling?
- 显然您正在使用的框架正在测试 HTTP 会话的可序列化性 (
com.csdcsystems.amanda.servlet.AmandaSessionFilter.testSerializability
) - 并且您的会话(
org.zkoss.zk.ui.http.SerializableSession
类型)似乎在内部定义了一个匿名BaseClass
。 - 会话中的每个对象都必须是可序列化的,因此您会收到此错误。