Program: 86051
Project: 86051
Buggy source:
@Override public void doFilter(ServletRequest pRequest,ServletResponse pResponse,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)pRequest;
  if (httpRequest.getMethod().equalsIgnoreCase("String_Node_Str")) {
    chain.doFilter(pRequest,pResponse);
    return;
  }
  HttpSession sessionHTTP=httpRequest.getSession();
  Account account=(Account)sessionHTTP.getAttribute("String_Node_Str");
  String qs=httpRequest.getQueryString();
  String originURL=httpRequest.getRequestURI() + (qs == null ? "String_Node_Str" : "String_Node_Str" + qs);
  int offset=httpRequest.getContextPath().equals("String_Node_Str") ? 2 : 3;
  String requestURI=httpRequest.getRequestURI();
  String[] pathInfo=Pattern.compile("String_Node_Str").split(requestURI);
  String fullName="String_Node_Str";
  String workspaceId="String_Node_Str";
  String elementType="String_Node_Str";
  String fileName="String_Node_Str";
  int iteration=0;
  BinaryResource binaryResource=null;
  DocumentIteration docI=null;
  User user=null;
  boolean isSubResource=false;
  boolean needsCacheHeaders=false;
  String outputFormat=pRequest.getParameter("String_Node_Str");
  boolean isDocumentAndOutputSpecified=outputFormat != null && !outputFormat.isEmpty();
  String subResourceVirtualPath="String_Node_Str";
  boolean isPrivateSharedFile=URLDecoder.decode(pathInfo[offset - 1],"String_Node_Str").equals("String_Node_Str");
  if (!isPrivateSharedFile) {
    try {
      workspaceId=URLDecoder.decode(pathInfo[offset],"String_Node_Str");
      elementType=URLDecoder.decode(pathInfo[offset + 1],"String_Node_Str");
      if (elementType.equals("String_Node_Str")) {
        needsCacheHeaders=true;
        String docMId=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
        String docMVersion=pathInfo[offset + 3];
        iteration=Integer.parseInt(pathInfo[offset + 4]);
        fileName=URLDecoder.decode(pathInfo[offset + 5],"String_Node_Str");
        fullName=workspaceId + "String_Node_Str" + elementType+ "String_Node_Str"+ docMId+ "String_Node_Str"+ docMVersion+ "String_Node_Str"+ iteration+ "String_Node_Str"+ fileName;
        if (account != null) {
          binaryResource=documentService.getBinaryResource(fullName);
          docI=documentService.findDocumentIterationByBinaryResource(binaryResource);
          user=documentService.whoAmI(workspaceId);
        }
 else {
          DocumentMasterKey docMK=new DocumentMasterKey(workspaceId,docMId,docMVersion);
          binaryResource=guestProxy.getPublicBinaryResourceForDocument(docMK,fullName);
          docI=guestProxy.findDocumentIterationByBinaryResource(binaryResource);
          user=guestProxy.whoAmI();
        }
        if (pathInfo.length > offset + 6) {
          String[] pathInfosExtra=Arrays.copyOfRange(pathInfo,offset + 6,pathInfo.length);
          isSubResource=true;
          subResourceVirtualPath=documentResourceGetterService.getSubResourceVirtualPath(binaryResource,StringUtils.join(pathInfosExtra,'/'));
        }
      }
 else       if (elementType.equals("String_Node_Str")) {
        needsCacheHeaders=true;
        String partNumber=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
        String version=pathInfo[offset + 3];
        iteration=Integer.parseInt(pathInfo[offset + 4]);
        if (pathInfo.length == offset + 7) {
          fileName=URLDecoder.decode(pathInfo[offset + 6],"String_Node_Str");
          String subType=URLDecoder.decode(pathInfo[offset + 5],"String_Node_Str");
          fullName=workspaceId + "String_Node_Str" + elementType+ "String_Node_Str"+ partNumber+ "String_Node_Str"+ version+ "String_Node_Str"+ iteration+ "String_Node_Str"+ subType+ "String_Node_Str"+ fileName;
        }
 else {
          fileName=URLDecoder.decode(pathInfo[offset + 5],"String_Node_Str");
          fullName=workspaceId + "String_Node_Str" + elementType+ "String_Node_Str"+ partNumber+ "String_Node_Str"+ version+ "String_Node_Str"+ iteration+ "String_Node_Str"+ fileName;
        }
        if (account != null) {
          binaryResource=productService.getBinaryResource(fullName);
        }
 else {
          PartRevisionKey partK=new PartRevisionKey(workspaceId,partNumber,version);
          binaryResource=guestProxy.getPublicBinaryResourceForPart(partK,fullName);
        }
      }
 else       if (elementType.equals("String_Node_Str")) {
        String templateID=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
        fileName=URLDecoder.decode(pathInfo[offset + 3],"String_Node_Str");
        fullName=workspaceId + "String_Node_Str" + elementType+ "String_Node_Str"+ templateID+ "String_Node_Str"+ fileName;
        binaryResource=documentService.getBinaryResource(fullName);
      }
 else       if (elementType.equals("String_Node_Str")) {
        String templateID=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
        fileName=URLDecoder.decode(pathInfo[offset + 3],"String_Node_Str");
        fullName=workspaceId + "String_Node_Str" + elementType+ "String_Node_Str"+ templateID+ "String_Node_Str"+ fileName;
        binaryResource=documentService.getBinaryResource(fullName);
      }
      pRequest.setAttribute("String_Node_Str",binaryResource);
      pRequest.setAttribute("String_Node_Str",isSubResource);
      pRequest.setAttribute("String_Node_Str",isDocumentAndOutputSpecified);
      pRequest.setAttribute("String_Node_Str",fullName);
      pRequest.setAttribute("String_Node_Str",outputFormat);
      pRequest.setAttribute("String_Node_Str",subResourceVirtualPath);
      pRequest.setAttribute("String_Node_Str",needsCacheHeaders);
      pRequest.setAttribute("String_Node_Str",user);
      pRequest.setAttribute("String_Node_Str",docI);
      chain.doFilter(pRequest,pResponse);
    }
 catch (    LoginException pEx) {
      httpRequest.getRequestDispatcher("String_Node_Str" + URLEncoder.encode(originURL,"String_Node_Str")).forward(pRequest,pResponse);
    }
catch (    Exception pEx) {
      throw new ServletException("String_Node_Str",pEx);
    }
  }
 else {
    try {
      String uuid=URLDecoder.decode(pathInfo[offset],"String_Node_Str");
      iteration=Integer.valueOf(URLDecoder.decode(pathInfo[offset + 1],"String_Node_Str"));
      SharedEntity sharedEntity=shareService.findSharedEntityForGivenUUID(uuid);
      workspaceId=sharedEntity.getWorkspace().getId();
      if (sharedEntity.getExpireDate() != null && sharedEntity.getExpireDate().getTime() < new Date().getTime()) {
        shareService.deleteSharedEntityIfExpired(sharedEntity);
        pRequest.getRequestDispatcher("String_Node_Str").forward(pRequest,pResponse);
        return;
      }
      if (sharedEntity instanceof SharedDocument) {
        DocumentMaster docM=((SharedDocument)sharedEntity).getDocumentMaster();
        docI=docM.getLastIteration();
        String docMId=docM.getId();
        String docMVersion=docM.getVersion();
        iteration=Integer.valueOf(URLDecoder.decode(pathInfo[offset + 1],"String_Node_Str"));
        fileName=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
        fullName=workspaceId + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ docMId+ "String_Node_Str"+ docMVersion+ "String_Node_Str"+ iteration+ "String_Node_Str"+ fileName;
        if (account != null) {
          binaryResource=documentService.getBinaryResource(fullName);
          docI=documentService.findDocumentIterationByBinaryResource(binaryResource);
          user=documentService.whoAmI(workspaceId);
        }
 else {
          binaryResource=guestProxy.getBinaryResourceForSharedDocument(fullName);
          docI=guestProxy.findDocumentIterationByBinaryResource(binaryResource);
          user=guestProxy.whoAmI();
        }
        if (pathInfo.length > offset + 3) {
          String[] pathInfosExtra=Arrays.copyOfRange(pathInfo,offset + 3,pathInfo.length);
          isSubResource=true;
          subResourceVirtualPath=documentResourceGetterService.getSubResourceVirtualPath(binaryResource,StringUtils.join(pathInfosExtra,'/'));
        }
      }
 else       if (sharedEntity instanceof SharedPart) {
        PartRevision partRevision=((SharedPart)sharedEntity).getPartRevision();
        String partNumber=partRevision.getPartNumber();
        String version=partRevision.getVersion();
        iteration=Integer.valueOf(URLDecoder.decode(pathInfo[offset + 1],"String_Node_Str"));
        if (pathInfo.length == offset + 4) {
          fileName=URLDecoder.decode(pathInfo[offset + 3],"String_Node_Str");
          String subType=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
          fullName=workspaceId + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ partNumber+ "String_Node_Str"+ version+ "String_Node_Str"+ iteration+ "String_Node_Str"+ subType+ "String_Node_Str"+ fileName;
        }
 else {
          fileName=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
          fullName=workspaceId + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ partNumber+ "String_Node_Str"+ version+ "String_Node_Str"+ iteration+ "String_Node_Str"+ fileName;
        }
        if (account != null) {
          binaryResource=productService.getBinaryResource(fullName);
        }
 else {
          binaryResource=guestProxy.getBinaryResourceForSharedPart(fullName);
        }
      }
      pRequest.setAttribute("String_Node_Str",binaryResource);
      pRequest.setAttribute("String_Node_Str",isSubResource);
      pRequest.setAttribute("String_Node_Str",isDocumentAndOutputSpecified);
      pRequest.setAttribute("String_Node_Str",fullName);
      pRequest.setAttribute("String_Node_Str",outputFormat);
      pRequest.setAttribute("String_Node_Str",subResourceVirtualPath);
      pRequest.setAttribute("String_Node_Str",needsCacheHeaders);
      pRequest.setAttribute("String_Node_Str",user);
      pRequest.setAttribute("String_Node_Str",docI);
      chain.doFilter(pRequest,pResponse);
    }
 catch (    Exception e) {
      httpRequest.getRequestDispatcher("String_Node_Str" + URLEncoder.encode(originURL,"String_Node_Str")).forward(pRequest,pResponse);
    }
  }
}

Fixed version (ground truth):
@Override public void doFilter(ServletRequest pRequest,ServletResponse pResponse,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)pRequest;
  if (httpRequest.getMethod().equalsIgnoreCase("String_Node_Str")) {
    chain.doFilter(pRequest,pResponse);
    return;
  }
  HttpSession sessionHTTP=httpRequest.getSession();
  Account account=(Account)sessionHTTP.getAttribute("String_Node_Str");
  String qs=httpRequest.getQueryString();
  String originURL=httpRequest.getRequestURI() + (qs == null ? "String_Node_Str" : "String_Node_Str" + qs);
  int offset=httpRequest.getContextPath().equals("String_Node_Str") ? 1 : 2;
  String requestURI=httpRequest.getRequestURI();
  String[] pathInfo=FilesFilter.removeEmptyEntries(requestURI.split("String_Node_Str"));
  String fullName="String_Node_Str";
  String workspaceId="String_Node_Str";
  String elementType="String_Node_Str";
  String fileName="String_Node_Str";
  int iteration=0;
  BinaryResource binaryResource=null;
  DocumentIteration docI=null;
  User user=null;
  boolean isSubResource=false;
  boolean needsCacheHeaders=false;
  String outputFormat=pRequest.getParameter("String_Node_Str");
  boolean isDocumentAndOutputSpecified=outputFormat != null && !outputFormat.isEmpty();
  String subResourceVirtualPath="String_Node_Str";
  boolean isPrivateSharedFile=URLDecoder.decode(pathInfo[offset - 1],"String_Node_Str").equals("String_Node_Str");
  if (!isPrivateSharedFile) {
    try {
      workspaceId=URLDecoder.decode(pathInfo[offset],"String_Node_Str");
      elementType=URLDecoder.decode(pathInfo[offset + 1],"String_Node_Str");
      if (elementType.equals("String_Node_Str")) {
        needsCacheHeaders=true;
        String docMId=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
        String docMVersion=pathInfo[offset + 3];
        iteration=Integer.parseInt(pathInfo[offset + 4]);
        fileName=URLDecoder.decode(pathInfo[offset + 5],"String_Node_Str");
        fullName=workspaceId + "String_Node_Str" + elementType+ "String_Node_Str"+ docMId+ "String_Node_Str"+ docMVersion+ "String_Node_Str"+ iteration+ "String_Node_Str"+ fileName;
        if (account != null) {
          binaryResource=documentService.getBinaryResource(fullName);
          docI=documentService.findDocumentIterationByBinaryResource(binaryResource);
          user=documentService.whoAmI(workspaceId);
        }
 else {
          DocumentMasterKey docMK=new DocumentMasterKey(workspaceId,docMId,docMVersion);
          binaryResource=guestProxy.getPublicBinaryResourceForDocument(docMK,fullName);
          docI=guestProxy.findDocumentIterationByBinaryResource(binaryResource);
          user=guestProxy.whoAmI();
        }
        if (pathInfo.length > offset + 6) {
          String[] pathInfosExtra=Arrays.copyOfRange(pathInfo,offset + 6,pathInfo.length);
          isSubResource=true;
          subResourceVirtualPath=documentResourceGetterService.getSubResourceVirtualPath(binaryResource,StringUtils.join(pathInfosExtra,'/'));
        }
      }
 else       if (elementType.equals("String_Node_Str")) {
        needsCacheHeaders=true;
        String partNumber=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
        String version=pathInfo[offset + 3];
        iteration=Integer.parseInt(pathInfo[offset + 4]);
        if (pathInfo.length == offset + 7) {
          fileName=URLDecoder.decode(pathInfo[offset + 6],"String_Node_Str");
          String subType=URLDecoder.decode(pathInfo[offset + 5],"String_Node_Str");
          fullName=workspaceId + "String_Node_Str" + elementType+ "String_Node_Str"+ partNumber+ "String_Node_Str"+ version+ "String_Node_Str"+ iteration+ "String_Node_Str"+ subType+ "String_Node_Str"+ fileName;
        }
 else {
          fileName=URLDecoder.decode(pathInfo[offset + 5],"String_Node_Str");
          fullName=workspaceId + "String_Node_Str" + elementType+ "String_Node_Str"+ partNumber+ "String_Node_Str"+ version+ "String_Node_Str"+ iteration+ "String_Node_Str"+ fileName;
        }
        if (account != null) {
          binaryResource=productService.getBinaryResource(fullName);
        }
 else {
          PartRevisionKey partK=new PartRevisionKey(workspaceId,partNumber,version);
          binaryResource=guestProxy.getPublicBinaryResourceForPart(partK,fullName);
        }
      }
 else       if (elementType.equals("String_Node_Str")) {
        String templateID=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
        fileName=URLDecoder.decode(pathInfo[offset + 3],"String_Node_Str");
        fullName=workspaceId + "String_Node_Str" + elementType+ "String_Node_Str"+ templateID+ "String_Node_Str"+ fileName;
        binaryResource=documentService.getBinaryResource(fullName);
      }
 else       if (elementType.equals("String_Node_Str")) {
        String templateID=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
        fileName=URLDecoder.decode(pathInfo[offset + 3],"String_Node_Str");
        fullName=workspaceId + "String_Node_Str" + elementType+ "String_Node_Str"+ templateID+ "String_Node_Str"+ fileName;
        binaryResource=documentService.getBinaryResource(fullName);
      }
      pRequest.setAttribute("String_Node_Str",binaryResource);
      pRequest.setAttribute("String_Node_Str",isSubResource);
      pRequest.setAttribute("String_Node_Str",isDocumentAndOutputSpecified);
      pRequest.setAttribute("String_Node_Str",fullName);
      pRequest.setAttribute("String_Node_Str",outputFormat);
      pRequest.setAttribute("String_Node_Str",subResourceVirtualPath);
      pRequest.setAttribute("String_Node_Str",needsCacheHeaders);
      pRequest.setAttribute("String_Node_Str",user);
      pRequest.setAttribute("String_Node_Str",docI);
      chain.doFilter(pRequest,pResponse);
    }
 catch (    LoginException pEx) {
      httpRequest.getRequestDispatcher("String_Node_Str" + URLEncoder.encode(originURL,"String_Node_Str")).forward(pRequest,pResponse);
    }
catch (    Exception pEx) {
      throw new ServletException("String_Node_Str",pEx);
    }
  }
 else {
    try {
      String uuid=URLDecoder.decode(pathInfo[offset],"String_Node_Str");
      iteration=Integer.valueOf(URLDecoder.decode(pathInfo[offset + 1],"String_Node_Str"));
      SharedEntity sharedEntity=shareService.findSharedEntityForGivenUUID(uuid);
      workspaceId=sharedEntity.getWorkspace().getId();
      if (sharedEntity.getExpireDate() != null && sharedEntity.getExpireDate().getTime() < new Date().getTime()) {
        shareService.deleteSharedEntityIfExpired(sharedEntity);
        pRequest.getRequestDispatcher("String_Node_Str").forward(pRequest,pResponse);
        return;
      }
      if (sharedEntity instanceof SharedDocument) {
        DocumentMaster docM=((SharedDocument)sharedEntity).getDocumentMaster();
        docI=docM.getLastIteration();
        String docMId=docM.getId();
        String docMVersion=docM.getVersion();
        iteration=Integer.valueOf(URLDecoder.decode(pathInfo[offset + 1],"String_Node_Str"));
        fileName=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
        fullName=workspaceId + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ docMId+ "String_Node_Str"+ docMVersion+ "String_Node_Str"+ iteration+ "String_Node_Str"+ fileName;
        if (account != null) {
          binaryResource=documentService.getBinaryResource(fullName);
          docI=documentService.findDocumentIterationByBinaryResource(binaryResource);
          user=documentService.whoAmI(workspaceId);
        }
 else {
          binaryResource=guestProxy.getBinaryResourceForSharedDocument(fullName);
          docI=guestProxy.findDocumentIterationByBinaryResource(binaryResource);
          user=guestProxy.whoAmI();
        }
        if (pathInfo.length > offset + 3) {
          String[] pathInfosExtra=Arrays.copyOfRange(pathInfo,offset + 3,pathInfo.length);
          isSubResource=true;
          subResourceVirtualPath=documentResourceGetterService.getSubResourceVirtualPath(binaryResource,StringUtils.join(pathInfosExtra,'/'));
        }
      }
 else       if (sharedEntity instanceof SharedPart) {
        PartRevision partRevision=((SharedPart)sharedEntity).getPartRevision();
        String partNumber=partRevision.getPartNumber();
        String version=partRevision.getVersion();
        iteration=Integer.valueOf(URLDecoder.decode(pathInfo[offset + 1],"String_Node_Str"));
        if (pathInfo.length == offset + 4) {
          fileName=URLDecoder.decode(pathInfo[offset + 3],"String_Node_Str");
          String subType=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
          fullName=workspaceId + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ partNumber+ "String_Node_Str"+ version+ "String_Node_Str"+ iteration+ "String_Node_Str"+ subType+ "String_Node_Str"+ fileName;
        }
 else {
          fileName=URLDecoder.decode(pathInfo[offset + 2],"String_Node_Str");
          fullName=workspaceId + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ partNumber+ "String_Node_Str"+ version+ "String_Node_Str"+ iteration+ "String_Node_Str"+ fileName;
        }
        if (account != null) {
          binaryResource=productService.getBinaryResource(fullName);
        }
 else {
          binaryResource=guestProxy.getBinaryResourceForSharedPart(fullName);
        }
      }
      pRequest.setAttribute("String_Node_Str",binaryResource);
      pRequest.setAttribute("String_Node_Str",isSubResource);
      pRequest.setAttribute("String_Node_Str",isDocumentAndOutputSpecified);
      pRequest.setAttribute("String_Node_Str",fullName);
      pRequest.setAttribute("String_Node_Str",outputFormat);
      pRequest.setAttribute("String_Node_Str",subResourceVirtualPath);
      pRequest.setAttribute("String_Node_Str",needsCacheHeaders);
      pRequest.setAttribute("String_Node_Str",user);
      pRequest.setAttribute("String_Node_Str",docI);
      chain.doFilter(pRequest,pResponse);
    }
 catch (    Exception e) {
      httpRequest.getRequestDispatcher("String_Node_Str" + URLEncoder.encode(originURL,"String_Node_Str")).forward(pRequest,pResponse);
    }
  }
}