Jetty
  1. Jetty
  2. JETTY-1259

NullPointerException in JDBCSessionIdManager when invalidating session

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 7.1.6
    • Fix Version/s: 7.3.0
    • Component/s: Servlet
    • Labels:
      None
    • Patch Submitted:
      Yes
    • Number of attachments :
      0

      Description

      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();
      ------------------------------------------------------------------------

        Activity

        Hide
        Thor Harald Johansen added a comment -

        JIRA seems to have messed up the line breaks. Hopefully the code is still readable.

        Show
        Thor Harald Johansen added a comment - JIRA seems to have messed up the line breaks. Hopefully the code is still readable.
        Hide
        Jan Bartel added a comment -

        Good point.

        Fixed in r2292.

        Show
        Jan Bartel added a comment - Good point. Fixed in r2292.
        Hide
        Kevin Jordan added a comment -

        Fix also needs to be applied in scavenge method.

        Show
        Kevin Jordan added a comment - Fix also needs to be applied in scavenge method.
        Hide
        Jan Bartel added a comment -

        Drats. Good point.

        Show
        Jan Bartel added a comment - Drats. Good point.
        Hide
        Jan Bartel added a comment -

        Fixed in svn rev 2647.

        Show
        Jan Bartel added a comment - Fixed in svn rev 2647.

          People

          • Assignee:
            Jan Bartel
            Reporter:
            Thor Harald Johansen
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: