wood burning stoves 2.0*
The moose likes Servlets and the fly likes How could a session attribute go missing without using removeAttribute() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How could a session attribute go missing without using removeAttribute()" Watch "How could a session attribute go missing without using removeAttribute()" New topic
Author

How could a session attribute go missing without using removeAttribute()

Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
Any ideas how a session attribute could go missing ?

MyObject myOb = session.getAttribute("myAttribute");
.......
.......
if (myOb.myMethod()){
.....
//print out session.getAttributeNames()

the second line of code above throws a null pointer, and when printing all the attributes in the session "myAttribute" does not exist. yet it has been definatly been set and no-where in the code is "removeAttribute()" used.
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
It's tough to answer this without seeing the code. Could you being setting in one session and getting in another? Your attribute name is hard-coded. Could there be a spelling mistake? (Case matters. Also use a constant rather than hard-coding) When setting, could you be setting the attribute to null? How do you know the setting "definitely worked"? Does it work sometimes but not others? If so, in what situations does it work and not work? Did it previously work but now doesn't? If so what changed to make it not work?
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
thanks for the help tom. I cannot provide sample code because its a massive app. there are numerous places it's being set and got. Its a tough one as I dont know what actions the user is making to cause this.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

The only ways this could happen is if the scoped variable is being removed by code, or different sessions are being queried.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
d edgar
Greenhorn

Joined: Apr 09, 2010
Posts: 4

How are you setting the Attribute? Are there any calls to invalidate? What does getMaxInactiveInterval() give?
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Mark Wa wrote:thanks for the help tom. I cannot provide sample code because its a massive app. there are numerous places it's being set and got. Its a tough one as I dont know what actions the user is making to cause this.

In that case I would add logging to the code to record user-generated events.
 
Consider Paul's rocket mass heater.
 
subject: How could a session attribute go missing without using removeAttribute()