While using the HttpServletRequest.getSession() methods in Servlets, I realized that the official documentation of the Servlet API indicates that HttpServletRequest.getSession() returns a new session object if the current session has expired or has been invalidated.
Also, HttpServletRequest.getSession(boolean createNew) returns a new session when createNew is true and if the previous session no longer exists.
Normally, IMO, while designing the API, one would have designed these methods as HttpServletRequest.getSession(true) creating a new session if the previous session is invalid and the HttpServletRequest.getSession() returning the existing session if present, else returning null.
Is there any specific reason pertaining to this significant difference in the API?
Applications are more likely to want the current session or to create a new one rather than the current session only if it exists. The API chosen by the Servlet EG is therefore written the way it is.