Exception loading sessions from persistent storage, extended

The method GDIApplication.setSessionAttribute (second stacktrace) calls getContextProperty("Session") which leads to an NPE?

The method ApplicationInstance.getContextProperty("Session") belongs to the Echo Framework (https://github.com/echo3/echo3). I'm not exactly sure how it gets hold of the Session object, but the ClassCastException in the first stacktrace might interfere with it.

Try replacing

((HttpSession) getContextProperty("Session")).setAttribute(name, value);

with

Connection conn = WebContainerServlet.getActiveConnection();
conn.getRequest().getSession().setAttribute(name, value);

This gives you access to the current ServletRequest and lets you retrieve the session using Java's ServletRequest.getSession() method, which will create the session if it doesn't yet exist.

As for the ClassCastException during session recreation: I don't know any other way than the ones you have already tried. But if the above tip works, these exceptions may still be annoying, but could turn out to be harmless. I confess, I normally ignore them when they appear...