#30 MockHttpServletRequest getSession semantics incorrect

Ken Koster

According to the HttpServletRequest API, a call to getSession() creates a new session if one has not been created. And a call to getSession(boolean) does not create a new one if none exists.

As implemented in version .4, getSession() returns a session only if one was previously set by setSession(), and getSession(false) will return a session only if getSession() has been called before (regardless of whether there was already a session in place).

I think this patch to the two methods would fix it:

public HttpSession getSession()
if (session == null) {
session = new MockHttpSession();
return session;

public HttpSession getSession(boolean create)
if(!create) return session;
return getSession();

The bug may also be in the WebMockObjectFactory.create*MockObjects* methods, but I don't know those methods well enough to be able to tell.


  • Alwin Ibba

    Alwin Ibba - 2008-01-22
    • assigned_to: nobody --> aibba
  • Alwin Ibba

    Alwin Ibba - 2008-01-22
    • status: open --> closed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks