Program: 155957
Project: 155957
Buggy source:
@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletResponse httpResponse=((HttpServletResponse)response);
  try {
    HttpSession session=((HttpServletRequest)request).getSession(false);
    Long userId=null;
    if (session != null) {
      userId=(Long)session.getAttribute(SessionResource.USER_ID_KEY);
      if (userId != null) {
        Context.getPermissionsManager().checkUserEnabled(userId);
        Context.getStatisticsManager().registerRequest(userId);
      }
    }
    if (userId == null) {
      httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
      return;
    }
    String path=((HttpServletRequest)request).getPathInfo();
    String[] parts=path.split("String_Node_Str");
    if (parts.length < 2 || parts.length == 2 && !path.endsWith("String_Node_Str")) {
      Context.getPermissionsManager().checkAdmin(userId);
    }
 else {
      Device device=Context.getDeviceManager().getByUniqueId(parts[1]);
      if (device != null) {
        Context.getPermissionsManager().checkDevice(userId,device.getId());
      }
 else {
        httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
      }
    }
    chain.doFilter(request,response);
  }
 catch (  SecurityException e) {
    httpResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
    httpResponse.getWriter().println(Log.exceptionStack(e));
  }
catch (  SQLException e) {
    httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    httpResponse.getWriter().println(Log.exceptionStack(e));
  }
}

Fixed version (ground truth):
@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletResponse httpResponse=(HttpServletResponse)response;
  try {
    HttpSession session=((HttpServletRequest)request).getSession(false);
    Long userId=null;
    if (session != null) {
      userId=(Long)session.getAttribute(SessionResource.USER_ID_KEY);
      if (userId != null) {
        Context.getPermissionsManager().checkUserEnabled(userId);
        Context.getStatisticsManager().registerRequest(userId);
      }
    }
    if (userId == null) {
      httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
      return;
    }
    String path=((HttpServletRequest)request).getPathInfo();
    String[] parts=path.split("String_Node_Str");
    if (parts.length < 2 || parts.length == 2 && !path.endsWith("String_Node_Str")) {
      Context.getPermissionsManager().checkAdmin(userId);
    }
 else {
      Device device=Context.getDeviceManager().getByUniqueId(parts[1]);
      if (device != null) {
        Context.getPermissionsManager().checkDevice(userId,device.getId());
      }
 else {
        httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
      }
    }
    chain.doFilter(request,response);
  }
 catch (  SecurityException e) {
    httpResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
    httpResponse.getWriter().println(Log.exceptionStack(e));
  }
catch (  SQLException e) {
    httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    httpResponse.getWriter().println(Log.exceptionStack(e));
  }
}