Program: 3228
Project: 3228
Buggy source:
/** 
 * Set up the bitstream reader. See the class description for information on configuration options.
 */
public void setup(SourceResolver resolver,Map objectModel,String src,Parameters par) throws ProcessingException, SAXException, IOException {
  super.setup(resolver,objectModel,src,par);
  try {
    this.request=ObjectModelHelper.getRequest(objectModel);
    this.response=ObjectModelHelper.getResponse(objectModel);
    Context context=ContextUtil.obtainContext(objectModel);
    int itemID=par.getParameterAsInteger("String_Node_Str",-1);
    int bitstreamID=par.getParameterAsInteger("String_Node_Str",-1);
    String handle=par.getParameter("String_Node_Str",null);
    int sequence=par.getParameterAsInteger("String_Node_Str",-1);
    String name=par.getParameter("String_Node_Str",null);
    this.isSpider=par.getParameter("String_Node_Str","String_Node_Str").equals("String_Node_Str");
    Bitstream bitstream=null;
    DSpaceObject dso=null;
    if (bitstreamID > -1) {
      bitstream=Bitstream.find(context,bitstreamID);
    }
 else     if (itemID > -1) {
      item=Item.find(context,itemID);
      if (sequence > -1) {
        bitstream=findBitstreamBySequence(item,sequence);
      }
 else       if (name != null) {
        bitstream=findBitstreamByName(item,name);
      }
    }
 else     if (handle != null) {
      dso=HandleManager.resolveToObject(context,handle);
      if (dso instanceof Item) {
        item=(Item)dso;
        if (sequence > -1) {
          bitstream=findBitstreamBySequence(item,sequence);
        }
 else         if (name != null) {
          bitstream=findBitstreamByName(item,name);
        }
      }
    }
    if ((sequence > -1 && bitstream == null) && name != null) {
      bitstream=findBitstreamByName(item,name);
      if (bitstream != null) {
        String redirectURL="String_Node_Str";
        if (item.getHandle() != null && item.getHandle().length() > 0) {
          redirectURL=request.getContextPath() + "String_Node_Str" + item.getHandle();
        }
 else {
          redirectURL=request.getContextPath() + "String_Node_Str" + item.getID();
        }
        redirectURL+="String_Node_Str" + name + "String_Node_Str"+ bitstream.getSequenceID();
        HttpServletResponse httpResponse=(HttpServletResponse)objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
        httpResponse.sendRedirect(redirectURL);
        return;
      }
    }
    if (bitstream == null) {
      throw new ResourceNotFoundException("String_Node_Str");
    }
    boolean isAuthorized=AuthorizeManager.authorizeActionBoolean(context,bitstream,Constants.READ);
    if (item != null && item.isWithdrawn() && !AuthorizeManager.isAdmin(context)) {
      isAuthorized=false;
      log.info(LogManager.getHeader(context,"String_Node_Str","String_Node_Str" + item.getHandle() + "String_Node_Str"));
    }
    if (!isAuthorized) {
      if (context.getCurrentUser() != null) {
        String redictURL=request.getContextPath() + "String_Node_Str";
        if (item != null) {
          redictURL+=item.getHandle();
        }
 else         if (dso != null) {
          redictURL+=dso.getHandle();
        }
        redictURL+="String_Node_Str" + bitstream.getID();
        HttpServletResponse httpResponse=(HttpServletResponse)objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
        httpResponse.sendRedirect(redictURL);
        return;
      }
 else {
        AuthenticationUtil.interruptRequest(objectModel,AUTH_REQUIRED_HEADER,AUTH_REQUIRED_MESSAGE,null);
        String redictURL=request.getContextPath() + "String_Node_Str";
        HttpServletResponse httpResponse=(HttpServletResponse)objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
        httpResponse.sendRedirect(redictURL);
        return;
      }
    }
    this.bitstreamInputStream=bitstream.retrieve();
    this.bitstreamSize=bitstream.getSize();
    this.bitstreamMimeType=bitstream.getFormat().getMIMEType();
    this.bitstreamName=bitstream.getName();
    if (context.getCurrentUser() == null) {
      this.isAnonymouslyReadable=true;
    }
 else {
      this.isAnonymouslyReadable=false;
      for (      ResourcePolicy rp : AuthorizeManager.getPoliciesActionFilter(context,bitstream,Constants.READ)) {
        if (rp.getGroupID() == 0) {
          this.isAnonymouslyReadable=true;
        }
      }
    }
    if (bitstreamName != null && bitstreamName.length() > 0) {
      int finalSlashIndex=bitstreamName.lastIndexOf('/');
      if (finalSlashIndex > 0) {
        bitstreamName=bitstreamName.substring(finalSlashIndex + 1);
      }
    }
 else {
      bitstreamName="String_Node_Str";
    }
    new DSpace().getEventService().fireEvent(new UsageEvent(UsageEvent.Action.VIEW,ObjectModelHelper.getRequest(objectModel),ContextUtil.obtainContext(ObjectModelHelper.getRequest(objectModel)),bitstream));
    context.complete();
  }
 catch (  SQLException sqle) {
    throw new ProcessingException("String_Node_Str",sqle);
  }
catch (  AuthorizeException ae) {
    throw new ProcessingException("String_Node_Str",ae);
  }
}

Fixed version (ground truth):
/** 
 * Set up the bitstream reader. See the class description for information on configuration options.
 */
public void setup(SourceResolver resolver,Map objectModel,String src,Parameters par) throws ProcessingException, SAXException, IOException {
  super.setup(resolver,objectModel,src,par);
  try {
    this.request=ObjectModelHelper.getRequest(objectModel);
    this.response=ObjectModelHelper.getResponse(objectModel);
    boolean BistreamReaderOpenedContext=!ContextUtil.isContextAvailable(objectModel);
    Context context=ContextUtil.obtainContext(objectModel);
    int itemID=par.getParameterAsInteger("String_Node_Str",-1);
    int bitstreamID=par.getParameterAsInteger("String_Node_Str",-1);
    String handle=par.getParameter("String_Node_Str",null);
    int sequence=par.getParameterAsInteger("String_Node_Str",-1);
    String name=par.getParameter("String_Node_Str",null);
    this.isSpider=par.getParameter("String_Node_Str","String_Node_Str").equals("String_Node_Str");
    Bitstream bitstream=null;
    DSpaceObject dso=null;
    if (bitstreamID > -1) {
      bitstream=Bitstream.find(context,bitstreamID);
    }
 else     if (itemID > -1) {
      item=Item.find(context,itemID);
      if (sequence > -1) {
        bitstream=findBitstreamBySequence(item,sequence);
      }
 else       if (name != null) {
        bitstream=findBitstreamByName(item,name);
      }
    }
 else     if (handle != null) {
      dso=HandleManager.resolveToObject(context,handle);
      if (dso instanceof Item) {
        item=(Item)dso;
        if (sequence > -1) {
          bitstream=findBitstreamBySequence(item,sequence);
        }
 else         if (name != null) {
          bitstream=findBitstreamByName(item,name);
        }
      }
    }
    if ((sequence > -1 && bitstream == null) && name != null) {
      bitstream=findBitstreamByName(item,name);
      if (bitstream != null) {
        String redirectURL="String_Node_Str";
        if (item.getHandle() != null && item.getHandle().length() > 0) {
          redirectURL=request.getContextPath() + "String_Node_Str" + item.getHandle();
        }
 else {
          redirectURL=request.getContextPath() + "String_Node_Str" + item.getID();
        }
        redirectURL+="String_Node_Str" + name + "String_Node_Str"+ bitstream.getSequenceID();
        HttpServletResponse httpResponse=(HttpServletResponse)objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
        httpResponse.sendRedirect(redirectURL);
        return;
      }
    }
    if (bitstream == null) {
      throw new ResourceNotFoundException("String_Node_Str");
    }
    boolean isAuthorized=AuthorizeManager.authorizeActionBoolean(context,bitstream,Constants.READ);
    if (item != null && item.isWithdrawn() && !AuthorizeManager.isAdmin(context)) {
      isAuthorized=false;
      log.info(LogManager.getHeader(context,"String_Node_Str","String_Node_Str" + item.getHandle() + "String_Node_Str"));
    }
    if (!isAuthorized) {
      if (context.getCurrentUser() != null) {
        String redictURL=request.getContextPath() + "String_Node_Str";
        if (item != null) {
          redictURL+=item.getHandle();
        }
 else         if (dso != null) {
          redictURL+=dso.getHandle();
        }
        redictURL+="String_Node_Str" + bitstream.getID();
        HttpServletResponse httpResponse=(HttpServletResponse)objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
        httpResponse.sendRedirect(redictURL);
        return;
      }
 else {
        AuthenticationUtil.interruptRequest(objectModel,AUTH_REQUIRED_HEADER,AUTH_REQUIRED_MESSAGE,null);
        String redictURL=request.getContextPath() + "String_Node_Str";
        HttpServletResponse httpResponse=(HttpServletResponse)objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
        httpResponse.sendRedirect(redictURL);
        return;
      }
    }
    this.bitstreamInputStream=bitstream.retrieve();
    this.bitstreamSize=bitstream.getSize();
    this.bitstreamMimeType=bitstream.getFormat().getMIMEType();
    this.bitstreamName=bitstream.getName();
    if (context.getCurrentUser() == null) {
      this.isAnonymouslyReadable=true;
    }
 else {
      this.isAnonymouslyReadable=false;
      for (      ResourcePolicy rp : AuthorizeManager.getPoliciesActionFilter(context,bitstream,Constants.READ)) {
        if (rp.getGroupID() == 0) {
          this.isAnonymouslyReadable=true;
        }
      }
    }
    if (bitstreamName != null && bitstreamName.length() > 0) {
      int finalSlashIndex=bitstreamName.lastIndexOf('/');
      if (finalSlashIndex > 0) {
        bitstreamName=bitstreamName.substring(finalSlashIndex + 1);
      }
    }
 else {
      bitstreamName="String_Node_Str";
    }
    new DSpace().getEventService().fireEvent(new UsageEvent(UsageEvent.Action.VIEW,ObjectModelHelper.getRequest(objectModel),ContextUtil.obtainContext(ObjectModelHelper.getRequest(objectModel)),bitstream));
    if (BistreamReaderOpenedContext)     context.complete();
  }
 catch (  SQLException sqle) {
    throw new ProcessingException("String_Node_Str",sqle);
  }
catch (  AuthorizeException ae) {
    throw new ProcessingException("String_Node_Str",ae);
  }
}