Program: 28443
Project: 28443
Buggy source:
protected Session doGetSession(boolean create){
  if (context == null) {
    return null;
  }
  if (session != null && !session.isValid()) {
    session=null;
  }
  if (session != null) {
    return session;
  }
  Manager manager=context.getManager();
  if (manager == null) {
    return null;
  }
  if (requestedSessionId != null) {
    if (!checkUnsuccessfulSessionFind || !unsuccessfulSessionFind) {
      try {
        if (manager.isSessionVersioningSupported()) {
          session=manager.findSession(requestedSessionId,requestedSessionVersion);
          if (session instanceof StandardSession) {
            incrementSessionVersion((StandardSession)session,context);
          }
        }
 else {
          session=manager.findSession(requestedSessionId,this);
        }
        if (session == null) {
          unsuccessfulSessionFind=true;
        }
      }
 catch (      IOException e) {
        session=null;
      }
    }
    if (session != null && !session.isValid()) {
      session=null;
    }
    if (session != null) {
      session.access();
      return session;
    }
  }
  if (!create) {
    return null;
  }
  if (context != null && response != null && context.getCookies() && response.getResponse().isCommitted()) {
    throw new IllegalStateException(rb.getString(CANNOT_CREATE_SESSION_EXCEPTION));
  }
  if (requestedSessionId != null && context.getReuseSessionID()) {
    session=manager.createSession(requestedSessionId);
    if (manager instanceof PersistentManagerBase) {
      ((PersistentManagerBase)manager).removeFromInvalidatedSessions(requestedSessionId);
    }
  }
 else   if (sessionTracker.getActiveSessions() > 0) {
synchronized (sessionTracker) {
      if (sessionTracker.getActiveSessions() > 0) {
        String id=sessionTracker.getSessionId();
        session=manager.createSession(id);
        if (manager instanceof PersistentManagerBase) {
          ((PersistentManagerBase)manager).removeFromInvalidatedSessions(id);
        }
      }
    }
  }
 else {
    String id=generateSessionId();
    if (id != null) {
      session=manager.createSession(id);
    }
 else {
      session=manager.createSession();
    }
  }
  StandardHost reqHost=(StandardHost)getHost();
  if (reqHost != null) {
    SingleSignOn sso=reqHost.getSingleSignOn();
    if (sso != null) {
      String ssoId=(String)getNote(org.apache.catalina.authenticator.Constants.REQ_SSOID_NOTE);
      if (ssoId != null) {
        long ssoVersion=0L;
        Long ssoVersionObj=(Long)getNote(org.apache.catalina.authenticator.Constants.REQ_SSO_VERSION_NOTE);
        if (ssoVersionObj != null) {
          ssoVersion=ssoVersionObj.longValue();
        }
        sso.associate(ssoId,ssoVersion,session);
        removeNote(org.apache.catalina.authenticator.Constants.REQ_SSOID_NOTE);
      }
    }
  }
  sessionTracker.track(session);
  if (session != null && getContext() != null) {
    if (manager.isSessionVersioningSupported()) {
      incrementSessionVersion((StandardSession)session,context);
    }
    if (getContext().getCookies()) {
      String jvmRoute=((StandardContext)getContext()).getJvmRoute();
      if (jvmRoute == null) {
        String id=session.getIdInternal();
        Cookie cookie=new Cookie(getContext().getSessionCookieName(),id);
        configureSessionCookie(cookie);
        ((HttpResponse)response).addSessionCookieInternal(cookie);
      }
    }
  }
  if (session != null) {
    session.access();
    return session;
  }
 else {
    return null;
  }
}

Fixed version (ground truth):
protected Session doGetSession(boolean create){
  if (context == null) {
    return null;
  }
  if (session != null && !session.isValid()) {
    session=null;
  }
  if (session != null) {
    return session;
  }
  Manager manager=context.getManager();
  if (manager == null) {
    return null;
  }
  if (requestedSessionId != null) {
    if (!checkUnsuccessfulSessionFind || !unsuccessfulSessionFind) {
      try {
        if (manager.isSessionVersioningSupported()) {
          session=manager.findSession(requestedSessionId,requestedSessionVersion);
          if (session instanceof StandardSession) {
            incrementSessionVersion((StandardSession)session,context);
          }
        }
 else {
          session=manager.findSession(requestedSessionId,this);
        }
        if (session == null) {
          unsuccessfulSessionFind=true;
        }
      }
 catch (      IOException e) {
        session=null;
      }
    }
    if (session != null && !session.isValid()) {
      session=null;
    }
    if (session != null) {
      session.access();
      return session;
    }
  }
  if (!create) {
    return null;
  }
  if (context != null && response != null && context.getCookies() && response.getResponse().isCommitted()) {
    throw new IllegalStateException(rb.getString(CANNOT_CREATE_SESSION_EXCEPTION));
  }
  if (requestedSessionId != null && context.getReuseSessionID()) {
    session=manager.createSession(requestedSessionId);
    if (manager instanceof PersistentManagerBase) {
      ((PersistentManagerBase)manager).removeFromInvalidatedSessions(requestedSessionId);
    }
  }
 else   if (sessionTracker.getActiveSessions() > 0) {
synchronized (sessionTracker) {
      if (sessionTracker.getActiveSessions() > 0) {
        String id=sessionTracker.getSessionId();
        session=manager.createSession(id);
        if (manager instanceof PersistentManagerBase) {
          ((PersistentManagerBase)manager).removeFromInvalidatedSessions(id);
        }
      }
    }
  }
 else {
    String id=generateSessionId();
    if (id != null) {
      session=manager.createSession(id);
    }
 else {
      session=manager.createSession();
    }
  }
  StandardHost reqHost=(StandardHost)getHost();
  if (reqHost != null) {
    SingleSignOn sso=reqHost.getSingleSignOn();
    if (sso != null) {
      String ssoId=(String)getNote(org.apache.catalina.authenticator.Constants.REQ_SSOID_NOTE);
      if (ssoId != null) {
        long ssoVersion=0L;
        Long ssoVersionObj=(Long)getNote(org.apache.catalina.authenticator.Constants.REQ_SSO_VERSION_NOTE);
        if (ssoVersionObj != null) {
          ssoVersion=ssoVersionObj.longValue();
        }
        sso.associate(ssoId,ssoVersion,session);
        removeNote(org.apache.catalina.authenticator.Constants.REQ_SSOID_NOTE);
      }
    }
  }
  sessionTracker.track(session);
  if (session != null && getContext() != null) {
    if (manager.isSessionVersioningSupported()) {
      incrementSessionVersion((StandardSession)session,context);
    }
    addSessionCookie();
  }
  if (session != null) {
    session.access();
    return session;
  }
 else {
    return null;
  }
}