简体   繁体   中英

Hitting java.lang.IllegalStateException: null when call setAttribute() in HttpSession

Good day,

The following is my java code:

Map< String, Account > accountMap = result.getAccountsMap( );
if ( accountMap != null )
    command.getSession( ).setAttribute( Constants.OA, accountMap ); 

And then on and off it will hitting IllegalStateException since today morning:

java.lang.IllegalStateException: null at com.ibm.ws.session.http.HttpSessionImpl.setAttribute(HttpSessionImpl.java:248) ~[com.ibm.ws.webcontainer.jar:na] at com.ibm.ws.session.SessionData.putSessionValue(SessionData.java:293) ~[com.ibm.ws.webcontainer.jar:na] at com.ibm.ws.session.SessionData.setAttribute(SessionData.java:217) ~[com.ibm.ws.webcontainer.jar:na] at com.ibm.ws.session.HttpSessionFacade.setAttribute(HttpSessionFacade.java:169) ~[com.ibm.ws.webcontainer.jar:na]

I tried to google about this, but its seems like a very common exception, and I have no idea how/where should I continue to troubleshoot.

This application is running on WAS 8.5.5.

Can anyone advise me on this?

I would guess that the session is invalid at this point. Can you add a check to isRequestedSessionIdValid() ? The fact that you're pulling it from a command object, rather than from an HttpServletRequest directly, means it could easily be an old, invalidated one.

That is correct, this was due to the method is called on an invalidated session:

https://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/http/HttpSession.html#setAttribute(java.lang.String,%20java.lang.Object)

HttpServletRequest.getSession(false) should also returns null at that point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM