Search code examples
javahttpjbosswildfly-10httpsession

What is difference between invalid and invalidated session


How sessions become invalid? Invalidated session is an invalid session? What is difference between invalid and invalidated session?
Why invalid session is not null?


Solution

  • When you invalidate the session, doesn't mean that the reference of the session become null.

    Invalidates this session then unbinds any objects bound to it.

    When you invalidate, it just remove all the data inside it and itself gets removed from the session pool. So when you ask for the session in current context, you don't receive any session as the session invalidated.

    Why invalid session is not null?

    If you have the session reference is in your hand, it can't be null. You can still access it, however the session data gets vanished. Once you again call/look for session, for ex request.getSession(false), you'll receive a null as session as the earlier session validated.