1
votes

I have class where all the inner classes are seralized something like this

public class BaseClass{
.......
......
.......
public class AccountPaymentDetailBean implements Serializable {
//inner class 
}

}

But i am getting below exception

java.io.NotSerializableException: com.core.shi.core.folder.BaseClass$5 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)

Could someone please tell me what is meaning of BaseClass$5 ? What this exception exactly telling ?

3
reference of base class instance to access base class fields and data, that is synthetic field generated by compilerPrashant
BaseClass$5 is a représentation of your object. BaseClass = instance of BaseClass class and 5 is the result of hashCode() method.zatenzu
Much better defintionSubodh Joshi
@zatenzu no, it's not. BaseClass$5 means that there is an anonymous class inside of BaseClass and the compiler choose the name "5" for this class. Hashcode of objects is prefixed with @.Absurd-Mind
@Absurd-Mind Damned! Sorry for my mistake. Thanks for your correction.zatenzu

3 Answers

1
votes

Could someone please tell me what is meaning of BaseClass$5?

The fifth anonymous inner class defined in BaseClass.

Anonymous inner classes are assigned an automatic name equal to the enclosing type, plus a dollar symbol, plus an ordinal. In your example: "BaseClass" + "$" + "5".

What this exception exactly telling?

  • Apparently the framework you are using is testing the serializability of the HTTP session (com.csdcsystems.amanda.servlet.AmandaSessionFilter.testSerializability)
  • AND your session (of type org.zkoss.zk.ui.http.SerializableSession) appears to have an anonymous BaseClass$5 defined inside.
  • Every object in a session must be serializable, so that's why you get this error.
2
votes

Q2) What this exception exactly telling ?
Inner classes should not implement Serializable. They use compiler-generated synthetic fields to store references to enclosing instances and to store values of local variables from enclosing scopes.
The default serialized form of an inner class is illdefined. A static member class can, however, implement Serializable.

More information here.

Q1) Could someone please tell me what is meaning of BaseClass$5 ?
There is no more further details. BAseClass$5 mean these exception occured in this class.

0
votes

Q1) Could someone please tell me what is meaning of BaseClass$5 ? sometimes innerclasses do not have names . in your case it has a name. A case where we directly create a class (e.g. implementor of a interface) on-the-fly and give implementation, and finish it with :); then that class does not gets a name. SO how do JVM creates a .class file for that??? - answer is $ naming convention. so such classes gets created as BaseClass$1, BaseClass$2 ...so on.

There must be at least 5 such inner unnames classes - check in your classes - which one gets which number?-> I think its purely on sequence. e.g. - clickListener is purely fictitious, example I tried to show...

public class myclass{
    public void mymethod(){
          this.addClickListener(new ClickListener(){
               public void click(){
                   S.O.P("Clicked !!!");
               }
          });
    }
}

So the implementation CLickListener gets compiled to-> myclass$1.class