13

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'
2787184
  • 3,749
  • 10
  • 47
  • 81

4 Answers4

15

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.

BHD
  • 151
  • 1
  • 3
  • 1
    Well this answer is the winner. Got the same problem. Found the file, and there was my custom config class missing the most important part: "implements Serializable" – horvoje Aug 07 '21 at 14:44
  • To find the file with sessions, you can put a breakpoint into org.apache.catalina.session.StandardManager inside method doLoad() on the line "try (FileInputStream fis = new FileInputStream(file.getAbsolutePath());". There you can find the current name and directory. – horvoje Aug 07 '21 at 14:48
  • 2
    There was a line in my tomcat log - before the exception and the stack trace - with a WARNING that gave the name of the class that couldn't be deserialized. Thanks to @horvoje for the "implements Serialiazable" but in my case the class already implements Serializable - anybody got any other ideas? – mwarren May 24 '22 at 09:50
  • 1
    ah, found it. It was a class of mine held **inside** the class mentioned in the log. i just added *implements Serializable* and it was done – mwarren May 24 '22 at 12:30
3

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.

0

I had this same problem and the exception was the unused HttpSession variable that I declare.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 25 '23 at 21:09
-1

I had the same problem. Seems to be a bug in Apache Tomcat 8.0.30 and maybe versions around it.

It worked for me in version 8.0.23 and then 8.5.8 as well.

Chris K.
  • 1,060
  • 8
  • 10