Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ClassCastException: java.io.ObjectStreamClass cannot be cast to java.lang.String

I am getting following stacktrace error while running web application on tomcat, unable to find root cause of this exception.

Eclipse 32 bit Luna Release (4.4.0)
Tomcat 32 bit 8.0.30
jdk1.8.0_66
    Jan 01, 2016 10:02:16 AM org.apache.catalina.session.StandardManager startInternal
SEVERE: Exception loading sessions from persistent storage
java.lang.ClassCastException: java.io.ObjectStreamClass cannot be cast to java.lang.String
    at java.io.ObjectInputStream.readTypeString(ObjectInputStream.java:1419)
    at java.io.ObjectStreamClass.readNonProxy(ObjectStreamClass.java:719)
    at java.io.ObjectInputStream.readClassDescriptor(ObjectInputStream.java:831)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1602)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
    at org.apache.catalina.session.StandardSession.doReadObject(StandardSession.java:1627)
    at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1090)
    at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:261)
    at org.apache.catalina.session.StandardManager.load(StandardManager.java:180)
    at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:460)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5272)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Jan 01, 2016 10:02:16 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'bgx'
like image 272
2787184 Avatar asked Jan 01 '16 04:01

2787184


People also ask

How do I resolve Java Lang ClassCastException error?

How to handle ClassCastException. To prevent the ClassCastException exception, one should be careful when casting objects to a specific class or interface and ensure that the target type is a child of the source type, and that the actual object is an instance of that type.

What is Java Lang ClassCastException?

Class ClassCastExceptionThrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a ClassCastException : Object x = new Integer(0); System. out. println((String)x);


2 Answers

I appear to have had the same problem but it was not a bug in Tomcat. It was due to an object belonging to the application being stored in the HTTP Session that was not serializable and which therefore Tomcat was unable to serialize when persisting sessions.

I suggest having a gawk at the contents of Tomcat's persistent sessions storage file: SESSIONS.ser, located in the Tomcat "work" directory for the corresponding Web Application.

Opening this binary file in a Text editor (when Tomcat has shutdown!), the presence of the string java.io.NotSerializableException will identify the serialization issue and the whereabouts in the file should give a clue as to which Object/field Tomcat was unable to serialize when persisting sessions.

like image 179
BHD Avatar answered Sep 17 '22 11:09

BHD


I have had the same issue. All I did to resolve the issue isis: First stop the tomcat, then right click on it and select Clean to clean the working directory of tomcat. Then I started it again without any errors.

like image 28
Tharakarama Reddy Y S Avatar answered Sep 21 '22 11:09

Tharakarama Reddy Y S