Wicket
  1. Wicket
  2. WICKET-5040

Session.exists() returns false when ThreadContext#session is not set to current session

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.5.0
    • Fix Version/s: 6.6.0
    • Component/s: wicket
    • Labels:
      None

      Description

      There are several places in Wicket which check for the existence of a Session before actually getting a reference to it, e.g. FeedbackCollector:

      public final List<FeedbackMessage> collect(final IFeedbackMessageFilter filter)
      {
      ...
      if (includeSession && Session.exists())

      { messages.addAll(Session.get().getFeedbackMessages().messages(filter)); }

      }

      If no one has called Session#get(), all calls to Session#exists() return false although a session might exist in the session store, i.e. it might just not be set to ThreadContext#session already.

        Issue Links

          Activity

          Sven Meier created issue -
          Sven Meier made changes -
          Field Original Value New Value
          Link This issue breaks WICKET-5036 [ WICKET-5036 ]
          Hide
          Sven Meier added a comment -

          With commit:80adc54 RestartResponseAtInterceptPageException.InterceptData#get() checks for existence of a session with Session#exists() before calling Session#get():

          if (Session.exists())

          { return Session.get().getMetaData(key); }

          return null;

          This was changed so that RestartResponseAtInterceptPageException#MAPPER doesn't create a (temporary) session if not needed (e.g. when a resource is requested).

          Note that Session#exists()'s javadoc is ambiguous about this detail:

          /**

          • Checks if the <code>Session</code> threadlocal is set in this thread
          • @return true if {@link Session#get()}

            can return the instance of session, false otherwise
            */
            public static boolean exists()

          It claims to return true if #get() can return the session. If there's a current session but it is not set on the ThreadContext yet, #exists() will return false, but #get() will return the session from the session store.

          Show
          Sven Meier added a comment - With commit:80adc54 RestartResponseAtInterceptPageException.InterceptData#get() checks for existence of a session with Session#exists() before calling Session#get(): if (Session.exists()) { return Session.get().getMetaData(key); } return null; This was changed so that RestartResponseAtInterceptPageException#MAPPER doesn't create a (temporary) session if not needed (e.g. when a resource is requested). Note that Session#exists()'s javadoc is ambiguous about this detail: /** Checks if the <code>Session</code> threadlocal is set in this thread @return true if {@link Session#get()} can return the instance of session, false otherwise */ public static boolean exists() It claims to return true if #get() can return the session. If there's a current session but it is not set on the ThreadContext yet, #exists() will return false, but #get() will return the session from the session store.
          Hide
          Sven Meier added a comment -

          Session#exists() now check session store too

          Show
          Sven Meier added a comment - Session#exists() now check session store too
          Sven Meier made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 6.6.0 [ 12323963 ]
          Resolution Fixed [ 1 ]

            People

            • Assignee:
              Sven Meier
              Reporter:
              Sven Meier
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development