[jetty-user] A possible bug in JDBCSessionIdManager

Thor Harald Johansen <[email protected]>
Newsgroups gmane.comp.java.jetty.support
Message-ID <[email protected]>
Hello, Jetty users,

This will be my first email to the group. I believe I have found a bit 
of an issue with the JDBCSessionIdManager in Jetty 7.0.2, 7.1.6 and 
possibly other versions.

There is a NullPointerException when one attempts to invalidate a session:

request.getSession().invalidate();

The source of the exception is line 374 (in version 7.1.6) of 
JDBCSessionIdManager.java:

http://download.eclipse.org/jetty/stable-7/xref/org/eclipse/jetty/server/session/JDBCSessionIdManager.html#374

I refactored the code around that line into a more debuggable form:
------------------------------------------------------------------------
Handler[] x = jettyServer.getChildHandlersByClass(ContextHandler.class);
for(int i = 0; x != null && i < x.length; i++) {
	ContextHandler ch = (ContextHandler) x[i];
	SessionHandler sh = (SessionHandler)
		ch.getChildHandlerByClass(SessionHandler.class);
	SessionManager sm = sh.getSessionManager(); // CRASH!
	// Original code continues below...
}
------------------------------------------------------------------------

Running this code causes a NullPointerException on the indicated line. 
The code seems to be wrongfully assuming that every ContextHandler has a 
SessionHandler associated to it. getChildHandlerByClass() presumably 
returns a NULL if no child handler of the specified class can be found. 
Predictably, calling getSessionManager() on this NULL pointer causes a 
run-time exception to be thrown.

I propose to modify the code inside the for() loop:
------------------------------------------------------------------------
SessionHandler handler = ((SessionHandler)((ContextHandler)contexts[i])
	.getChildHandlerByClass(SessionHandler.class));

if(handler == null) {
	/* No associated session handler, skip this child handler */
	continue;
}

SessionManager = handler.getSessionManager();
------------------------------------------------------------------------

This error is preventing me from storing sessions in the database. My 
website has thousands of users and the HashSessionManager takes a long 
time to load all the session files.

I will appreciate any feedback or help!

Regards,
Thor Harald Johansen
ArtGrounds.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.