Program: 145408
Project: 145408
Buggy source:
/** 
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
  if (!checkUpload(request,response)) {
    if (platypusCore != null) {
      HttpSession httpSession=request.getSession();
      if (httpSession != null) {
        AsyncContext async=request.startAsync();
        async.setTimeout(-1);
        Consumer<Session> requestProcessor=(        Session aSession) -> {
          try {
            Scripts.LocalContext context=Scripts.createContext(aSession.getSpace());
            context.setAsync(async);
            context.setRequest(request);
            context.setResponse(response);
            Scripts.setContext(context);
            try {
              DatabasesClient.getUserProperties(platypusCore.getDatabasesClient(),request.getUserPrincipal() != null ? request.getUserPrincipal().getName() : null,Scripts.getSpace(),(              Map<String,String> aUserProps) -> {
                String dataContext=aUserProps.get(ClientConstants.F_USR_CONTEXT);
                PlatypusPrincipal principal=servletRequestPrincipal(request,dataContext);
                context.setPrincipal(principal);
                Scripts.getSpace().process(() -> {
                  try {
                    processPlatypusRequest(request,response,httpSession,aSession,async);
                  }
 catch (                  Exception ex) {
                    Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.SEVERE,null,ex);
                    try {
                      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,ex.toString());
                      async.complete();
                    }
 catch (                    IOException|IllegalStateException ex1) {
                      Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.SEVERE,null,ex1);
                    }
                  }
                }
);
              }
,(              Exception ex) -> {
                try {
                  response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,ex.toString());
                  async.complete();
                }
 catch (                IOException|IllegalStateException ex1) {
                  Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.SEVERE,null,ex1);
                }
              }
);
            }
  finally {
              Scripts.setContext(null);
            }
          }
 catch (          Exception ex) {
            Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.SEVERE,null,ex);
            try {
              response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,ex.toString());
              async.complete();
            }
 catch (            IOException|IllegalStateException ex1) {
              Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.SEVERE,null,ex1);
            }
          }
        }
;
        Session session=platypusSessionByHttpSession(httpSession);
        if (session == null) {
          Scripts.LocalContext queueSpaceContext=Scripts.createContext(platypusCore.getQueueSpace());
          Scripts.setContext(queueSpaceContext);
          try {
            platypusCore.getQueueSpace().process(() -> {
              try {
                String platypusSessionId=(String)httpSession.getAttribute(PLATYPUS_SESSION_ID_ATTR_NAME);
                Session lookedup=platypusSessionId != null ? SessionManager.Singleton.instance.get(platypusSessionId) : null;
                if (lookedup == null) {
                  if (platypusSessionId == null) {
                    platypusSessionId=IDGenerator.genID() + "String_Node_Str";
                  }
                  lookedup=SessionManager.Singleton.instance.create(platypusSessionId);
                  httpSession.setAttribute(PLATYPUS_SESSION_ID_ATTR_NAME,platypusSessionId);
                  Logger.getLogger(PlatypusSessionsSynchronizer.class.getName()).log(Level.INFO,"String_Node_Str",lookedup.getId());
                }
                final Session effective=lookedup;
                requestProcessor.accept(effective);
              }
 catch (              ScriptException ex) {
                Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.SEVERE,null,ex);
              }
            }
);
          }
  finally {
            Scripts.setContext(null);
          }
        }
 else {
          requestProcessor.accept(session);
        }
      }
 else {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,HTTP_SESSION_MISSING_MSG);
      }
    }
 else {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,CORE_MISSING_MSG);
    }
  }
}

Fixed version (ground truth):
/** 
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
  if (!checkUpload(request,response)) {
    if (platypusCore != null) {
      HttpSession httpSession=request.getSession();
      if (httpSession != null) {
        AsyncContext async=request.startAsync();
        async.setTimeout(-1);
        Consumer<Session> requestProcessor=(        Session aSession) -> {
          String userName=request.getUserPrincipal() != null ? request.getUserPrincipal().getName() : null;
          Scripts.LocalContext context=Scripts.createContext(aSession.getSpace());
          context.setAsync(async);
          context.setRequest(request);
          context.setResponse(response);
          Scripts.setContext(context);
          try {
            Consumer<String> withDataContext=(dataContext) -> {
              PlatypusPrincipal principal=servletRequestPrincipal(request,dataContext);
              context.setPrincipal(principal);
              try {
                processPlatypusRequest(request,response,httpSession,aSession,async);
              }
 catch (              Exception ex) {
                Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.SEVERE,null,ex);
                try {
                  response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,ex.toString());
                  async.complete();
                }
 catch (                IOException|IllegalStateException ex1) {
                  Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.SEVERE,null,ex1);
                }
              }
            }
;
            try {
              DatabasesClient.getUserProperties(platypusCore.getDatabasesClient(),userName,Scripts.getSpace(),(              Map<String,String> aUserProps) -> {
                String dataContext=aUserProps.get(ClientConstants.F_USR_CONTEXT);
                withDataContext.accept(dataContext);
              }
,(              Exception ex) -> {
                Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.FINE,"String_Node_Str",new Object[]{userName,ex.toString()});
                withDataContext.accept(null);
              }
);
            }
 catch (            Exception ex) {
              Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.SEVERE,null,ex);
              try {
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,ex.toString());
                async.complete();
              }
 catch (              IOException|IllegalStateException ex1) {
                Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.SEVERE,null,ex1);
              }
            }
          }
  finally {
            Scripts.setContext(null);
          }
        }
;
        Session session=platypusSessionByHttpSession(httpSession);
        if (session == null) {
          Scripts.LocalContext queueSpaceContext=Scripts.createContext(platypusCore.getQueueSpace());
          Scripts.setContext(queueSpaceContext);
          try {
            platypusCore.getQueueSpace().process(() -> {
              try {
                String platypusSessionId=(String)httpSession.getAttribute(PLATYPUS_SESSION_ID_ATTR_NAME);
                Session lookedup=platypusSessionId != null ? SessionManager.Singleton.instance.get(platypusSessionId) : null;
                if (lookedup == null) {
                  if (platypusSessionId == null) {
                    platypusSessionId=IDGenerator.genID() + "String_Node_Str";
                  }
                  lookedup=SessionManager.Singleton.instance.create(platypusSessionId);
                  httpSession.setAttribute(PLATYPUS_SESSION_ID_ATTR_NAME,platypusSessionId);
                  Logger.getLogger(PlatypusSessionsSynchronizer.class.getName()).log(Level.INFO,"String_Node_Str",lookedup.getId());
                }
                final Session effective=lookedup;
                requestProcessor.accept(effective);
              }
 catch (              ScriptException ex) {
                Logger.getLogger(PlatypusHttpServlet.class.getName()).log(Level.SEVERE,null,ex);
              }
            }
);
          }
  finally {
            Scripts.setContext(null);
          }
        }
 else {
          requestProcessor.accept(session);
        }
      }
 else {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,HTTP_SESSION_MISSING_MSG);
      }
    }
 else {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,CORE_MISSING_MSG);
    }
  }
}