webtier@glassfish.java.net

Intermittent, but reproducible (!), corruption of the session map

From: <webtier_at_javadesktop.org>
Date: Tue, 13 Jul 2010 04:52:19 PDT

Hi, I've got something strange going on here.

My Mojarra 2.0.3 app stores a reference to a user entity in the session map
on successful login,

[code]
@ManagedProperty(value = "#{sessionScope}")
    private Map<String, Object> sessionMap;

...getters & setters ...

public User getCurrentUser() {
        return (User) getSessionMap().get("currentUser");
    }

    public void setCurrentUser(User currentUser) {
        SQLog.log();
        getSessionMap().remove("currentUser");
        if (currentUser != null) {
            getSessionMap().put("currentUser", currentUser);
        }
    }
[/code]

What I'm seeing is that after a code change and redeploy I will intermittently
get a version of the application that is trashing my stored user reference. I've
got an excerpt from the server log below. This shows that the app is logging a
call to setCurrentUser (the numbers are source line numbers). The loginAction()
method has successfully authenticated the user and I can see a session id
ending in 19751d and the user with username healeyb has been stored in the session map with the key "currentUser".

I then try to perform an operation via the GUI, I've not logged out (we'd have seen
a call to setCurrentUser() setting the user reference to null), I then try to get the
session id, and it's the same as before, ending in 19751d. I then try and get the
user reference but it's null (exception caused by attempt to access username from
null pointer).

SEVERE: SportQuest: uk.co.sportquest.jsfbeans.AbstractBackingBean.setCurrentUser:117
SEVERE: SportQuest: uk.co.sportquest.jsfbeans.LoginView.loginAction:51
SEVERE: Session Id: b75728894b1af5e07c396e19751d User: healeyb
SEVERE: SportQuest: uk.co.sportquest.jsfbeans.TeamView.createTeam:197
SEVERE: Session Id: b75728894b1af5e07c396e19751d
SEVERE: java.lang.NullPointerException

So the question is what's happened to the reference to the User instance I've
put in the session map with the key "currentUser"? I've not removed the map
entry or I'd see a call to setCurrentUser().

The interesting thing is that when I have a version of the app deployed that has
this problem it will do it every time. If I then force a rebuild and redeploy by, for
instance adding a space in the code of some arbitrary source code and then
removing the space, doing a Run Project in NetBeans I then get a version that
always works.

If anyone has any suggestions for further debugging tactics I'll give it a try, but
I'm at the limit of my knowledge in terms of how to progress this. I can't see any
reason why garbage collection would be an issue here as the entry in the session
map is a reference to the User instance?

Thanks,
Brendan.
[Message sent by forum member 'healeyb']

http://forums.java.net/jive/thread.jspa?messageID=477497