Program: 51769
Project: 51769
Buggy source:
/** 
 * Main service method for ShoppingServlet
 * @param req Object that encapsulates the request to the servlet
 * @param resp Object that encapsulates the response from the servlet
 */
public void performTask(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
  String action=null;
  action=req.getParameter(Util.ATTR_ACTION);
  Util.debug("String_Node_Str" + action);
  if (action.equals(ACTION_SHOPPING)) {
    String category=(String)req.getParameter("String_Node_Str");
    HttpSession session=req.getSession(true);
    if ((category == null) || (category.equals("String_Node_Str"))) {
      category=(String)session.getAttribute(Util.ATTR_CATEGORY);
    }
    if ((category == null) || (category.equals("String_Node_Str"))) {
      category="String_Node_Str";
    }
    session.setAttribute(Util.ATTR_CATEGORY,category);
    Collection c=catalog.getItemsByCategory(Integer.parseInt(category));
    ArrayList items=new ArrayList(c);
    for (int i=0; i < items.size(); ) {
      if (((Inventory)items.get(i)).isPublic())       i++;
 else       items.remove(i);
    }
    req.setAttribute(Util.ATTR_INVITEMS,items);
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_SHOPPING);
  }
 else   if (action.equals(ACTION_PRODUCTDETAIL)) {
    String invID=(String)req.getParameter("String_Node_Str");
    req.setAttribute(Util.ATTR_INVITEM,catalog.getItemInventory(invID));
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_PRODUCT);
  }
 else   if (action.equals(ACTION_GOTOCART)) {
    HttpSession session=req.getSession(true);
    ShoppingCart shoppingCart=(ShoppingCart)session.getAttribute(Util.ATTR_CART);
    if (shoppingCart != null) {
      try {
        shoppingCart.getItems();
      }
 catch (      RuntimeException e) {
        Util.debug("String_Node_Str");
        ShoppingCartContents cartContents=(ShoppingCartContents)session.getAttribute(Util.ATTR_CART_CONTENTS);
        shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
        session.setAttribute(Util.ATTR_CART,shoppingCart);
      }
    }
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_CART);
  }
 else   if (action.equals(ACTION_ADDTOCART)) {
    ShoppingCart shoppingCart=null;
    HttpSession session=req.getSession(true);
    shoppingCart=(ShoppingCart)session.getAttribute(Util.ATTR_CART);
    if (shoppingCart == null) {
      Util.debug("String_Node_Str");
      shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
    }
 else {
      try {
        Util.debug("String_Node_Str" + shoppingCart.getItems().size());
        shoppingCart.getItems();
      }
 catch (      RuntimeException e) {
        Util.debug("String_Node_Str");
        ShoppingCartContents cartContents=(ShoppingCartContents)session.getAttribute(Util.ATTR_CART_CONTENTS);
        shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
        if (cartContents != null) {
          shoppingCart.setCartContents(cartContents);
        }
      }
    }
    if (shoppingCart != null) {
      String invID=req.getParameter("String_Node_Str");
      Inventory inv=catalog.getItemInventory(invID);
      ShoppingCartItem si=new ShoppingCartItem(inv);
      si.setQuantity(Integer.parseInt(req.getParameter("String_Node_Str").trim()));
      shoppingCart.addItem(si);
      session.setAttribute(Util.ATTR_CART,shoppingCart);
      session.setAttribute(Util.ATTR_CART_CONTENTS,shoppingCart.getCartContents());
    }
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_CART);
  }
 else   if (action.equals(ACTION_UPDATEQUANTITY)) {
    HttpSession session=req.getSession(true);
    ShoppingCart shoppingCart=(ShoppingCart)session.getAttribute(Util.ATTR_CART);
    try {
      shoppingCart.getItems();
    }
 catch (    RuntimeException e) {
      Util.debug("String_Node_Str");
      ShoppingCartContents cartContents=(ShoppingCartContents)session.getAttribute(Util.ATTR_CART_CONTENTS);
      shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
      if (cartContents != null) {
        shoppingCart.setCartContents(cartContents);
      }
    }
    if (shoppingCart != null) {
      try {
        int cnt=0;
        Collection c=shoppingCart.getItems();
        ArrayList items;
        if (c instanceof ArrayList)         items=(ArrayList)c;
 else         items=new ArrayList(c);
        ShoppingCartItem si;
        String parm, parmval;
        for (int parmcnt=0; ; parmcnt++) {
          parm="String_Node_Str" + String.valueOf(parmcnt);
          parmval=req.getParameter(parm);
          if ((parmval == null) || parmval.equals("String_Node_Str")) {
            break;
          }
 else {
            int quantity=Integer.parseInt(parmval);
            if (quantity == 0) {
              items.remove(cnt);
            }
 else {
              si=(ShoppingCartItem)items.get(cnt);
              si.setQuantity(quantity);
              items.set(cnt,si);
              cnt++;
            }
          }
        }
        if (items.size() > 0) {
          shoppingCart.setItems(items);
          session.setAttribute(Util.ATTR_CART,shoppingCart);
          session.setAttribute(Util.ATTR_CART_CONTENTS,shoppingCart.getCartContents());
        }
 else {
          session.removeAttribute(Util.ATTR_CART);
          session.removeAttribute(Util.ATTR_CART_CONTENTS);
        }
      }
 catch (      Exception e) {
        Util.debug("String_Node_Str" + e);
        throw new ServletException(e.getMessage());
      }
    }
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_CART);
  }
 else   if (action.equals(ACTION_INITCHECKOUT)) {
    String url;
    HttpSession session=req.getSession(true);
    CustomerInfo customerInfo=(CustomerInfo)session.getAttribute(Util.ATTR_CUSTOMER);
    if (customerInfo == null) {
      req.setAttribute(Util.ATTR_RESULTS,"String_Node_Str");
      session.setAttribute(Util.ATTR_CHECKOUT,new Boolean(true));
      url=Util.PAGE_LOGIN;
    }
 else {
      url=Util.PAGE_ORDERINFO;
    }
    requestDispatch(getServletConfig().getServletContext(),req,resp,url);
  }
 else   if (action.equals(ACTION_ORDERINFODONE)) {
    OrderInfo orderinfo=null;
    ShoppingCart shoppingCart=null;
    HttpSession session=req.getSession(true);
    CustomerInfo customerInfo=(CustomerInfo)session.getAttribute(Util.ATTR_CUSTOMER);
    String customerID=customerInfo.getCustomerID();
    shoppingCart=(ShoppingCart)session.getAttribute(Util.ATTR_CART);
    try {
      Util.debug("String_Node_Str");
      shoppingCart.getItems();
    }
 catch (    RuntimeException e) {
      Util.debug("String_Node_Str");
      ShoppingCartContents cartContents=(ShoppingCartContents)session.getAttribute(Util.ATTR_CART_CONTENTS);
      if (cartContents != null) {
        shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
        shoppingCart.setCartContents(cartContents);
      }
 else {
        Util.debug("String_Node_Str");
        Util.debug("String_Node_Str");
        shoppingCart=null;
      }
    }
    Util.debug("String_Node_Str");
    if (shoppingCart != null) {
      Util.debug("String_Node_Str");
      String billName=req.getParameter("String_Node_Str");
      String billAddr1=req.getParameter("String_Node_Str");
      String billAddr2=req.getParameter("String_Node_Str");
      String billCity=req.getParameter("String_Node_Str");
      String billState=req.getParameter("String_Node_Str");
      String billZip=req.getParameter("String_Node_Str");
      String billPhone=req.getParameter("String_Node_Str");
      String shipName=req.getParameter("String_Node_Str");
      String shipAddr1=req.getParameter("String_Node_Str");
      String shipAddr2=req.getParameter("String_Node_Str");
      String shipCity=req.getParameter("String_Node_Str");
      String shipState=req.getParameter("String_Node_Str");
      String shipZip=req.getParameter("String_Node_Str");
      String shipPhone=req.getParameter("String_Node_Str");
      int shippingMethod=Integer.parseInt(req.getParameter("String_Node_Str"));
      String creditCard=req.getParameter("String_Node_Str");
      String ccNum=req.getParameter("String_Node_Str");
      String ccExpireMonth=req.getParameter("String_Node_Str");
      String ccExpireYear=req.getParameter("String_Node_Str");
      String cardHolder=req.getParameter("String_Node_Str");
      orderinfo=shoppingCart.createOrder(customerID,billName,billAddr1,billAddr2,billCity,billState,billZip,billPhone,shipName,shipAddr1,shipAddr2,shipCity,shipState,shipZip,shipPhone,creditCard,ccNum,ccExpireMonth,ccExpireYear,cardHolder,shippingMethod,shoppingCart.getItems());
      Util.debug("String_Node_Str");
    }
    if (orderinfo != null) {
      req.setAttribute(Util.ATTR_ORDERINFO,orderinfo);
      req.setAttribute(Util.ATTR_CARTITEMS,shoppingCart.getItems());
      session.setAttribute(Util.ATTR_ORDERKEY,orderinfo.getID());
      requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_CHECKOUTFINAL);
    }
  }
 else   if (action.equals(ACTION_COMPLETECHECKOUT)) {
    ShoppingCart shoppingCart=null;
    HttpSession session=req.getSession(true);
    String key=(String)session.getAttribute(Util.ATTR_ORDERKEY);
    req.setAttribute(Util.ATTR_ORDERID,key);
    String orderKey=key;
    Util.debug("String_Node_Str" + orderKey);
    CustomerInfo customerInfo=(CustomerInfo)session.getAttribute(Util.ATTR_CUSTOMER);
    shoppingCart=(ShoppingCart)session.getAttribute(Util.ATTR_CART);
    try {
      Util.debug("String_Node_Str");
      shoppingCart.getItems();
    }
 catch (    RuntimeException e) {
      Util.debug("String_Node_Str");
      ShoppingCartContents cartContents=(ShoppingCartContents)session.getAttribute(Util.ATTR_CART_CONTENTS);
      if (cartContents != null) {
        shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
        shoppingCart.setCartContents(cartContents);
      }
 else {
        Util.debug("String_Node_Str");
        Util.debug("String_Node_Str");
        shoppingCart=null;
      }
    }
    if (shoppingCart != null) {
      ShoppingCartItem si;
      Collection items=shoppingCart.getItems();
      for (      Object o : items) {
        si=(ShoppingCartItem)o;
        shoppingCart.checkInventory(si);
        Util.debug("String_Node_Str" + si.getID());
      }
    }
    try {
      mailer.createAndSendMail(customerInfo,orderKey);
    }
 catch (    MailerAppException e) {
      System.out.println("String_Node_Str" + e);
      e.printStackTrace();
    }
catch (    Exception e) {
      System.out.println("String_Node_Str" + e);
      e.printStackTrace();
    }
    session.removeAttribute(Util.ATTR_CART);
    session.removeAttribute(Util.ATTR_CART_CONTENTS);
    session.removeAttribute(Util.ATTR_CATEGORY);
    session.removeAttribute(Util.ATTR_ORDERKEY);
    session.removeAttribute(Util.ATTR_CHECKOUT);
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_ORDERDONE);
  }
}

Fixed version (ground truth):
/** 
 * Main service method for ShoppingServlet
 * @param req Object that encapsulates the request to the servlet
 * @param resp Object that encapsulates the response from the servlet
 */
public void performTask(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
  String action=null;
  action=req.getParameter(Util.ATTR_ACTION);
  Util.debug("String_Node_Str" + action);
  if (action.equals(ACTION_SHOPPING)) {
    String category=(String)req.getParameter("String_Node_Str");
    HttpSession session=req.getSession(true);
    if ((category == null) || (category.equals("String_Node_Str"))) {
      category=(String)session.getAttribute(Util.ATTR_CATEGORY);
    }
    if ((category == null) || (category.equals("String_Node_Str"))) {
      category="String_Node_Str";
    }
    session.setAttribute(Util.ATTR_CATEGORY,category);
    Collection c=catalog.getItemsByCategory(Integer.parseInt(category));
    ArrayList items=new ArrayList(c);
    for (int i=0; i < items.size(); ) {
      if (((Inventory)items.get(i)).isPublic())       i++;
 else       items.remove(i);
    }
    req.setAttribute(Util.ATTR_INVITEMS,items);
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_SHOPPING);
  }
 else   if (action.equals(ACTION_PRODUCTDETAIL)) {
    String invID=(String)req.getParameter("String_Node_Str");
    req.setAttribute(Util.ATTR_INVITEM,catalog.getItemInventory(invID));
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_PRODUCT);
  }
 else   if (action.equals(ACTION_GOTOCART)) {
    HttpSession session=req.getSession(true);
    ShoppingCart shoppingCart=(ShoppingCart)session.getAttribute(Util.ATTR_CART);
    if (shoppingCart != null) {
      try {
        shoppingCart.getItems();
      }
 catch (      RuntimeException e) {
        Util.debug("String_Node_Str");
        ShoppingCartContents cartContents=(ShoppingCartContents)session.getAttribute(Util.ATTR_CART_CONTENTS);
        shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
        session.setAttribute(Util.ATTR_CART,shoppingCart);
      }
    }
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_CART);
  }
 else   if (action.equals(ACTION_ADDTOCART)) {
    ShoppingCart shoppingCart=null;
    HttpSession session=req.getSession(true);
    shoppingCart=(ShoppingCart)session.getAttribute(Util.ATTR_CART);
    if (shoppingCart == null) {
      Util.debug("String_Node_Str");
      shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
    }
 else {
      try {
        Util.debug("String_Node_Str" + shoppingCart.getItems().size());
        shoppingCart.getItems();
      }
 catch (      RuntimeException e) {
        Util.debug("String_Node_Str");
        ShoppingCartContents cartContents=(ShoppingCartContents)session.getAttribute(Util.ATTR_CART_CONTENTS);
        shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
        if (cartContents != null) {
          shoppingCart.setCartContents(cartContents);
        }
      }
    }
    if (shoppingCart != null) {
      String invID=req.getParameter("String_Node_Str");
      Inventory inv=catalog.getItemInventory(invID);
      ShoppingCartItem si=new ShoppingCartItem(inv);
      si.setQuantity(Integer.parseInt(req.getParameter("String_Node_Str").trim()));
      shoppingCart.addItem(si);
      session.setAttribute(Util.ATTR_CART,shoppingCart);
      session.setAttribute(Util.ATTR_CART_CONTENTS,shoppingCart.getCartContents());
    }
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_CART);
  }
 else   if (action.equals(ACTION_UPDATEQUANTITY)) {
    HttpSession session=req.getSession(true);
    ShoppingCart shoppingCart=(ShoppingCart)session.getAttribute(Util.ATTR_CART);
    try {
      shoppingCart.getItems();
    }
 catch (    RuntimeException e) {
      Util.debug("String_Node_Str");
      ShoppingCartContents cartContents=(ShoppingCartContents)session.getAttribute(Util.ATTR_CART_CONTENTS);
      shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
      if (cartContents != null) {
        shoppingCart.setCartContents(cartContents);
      }
    }
    if (shoppingCart != null) {
      try {
        int cnt=0;
        Collection c=shoppingCart.getItems();
        ArrayList items;
        if (c instanceof ArrayList)         items=(ArrayList)c;
 else         items=new ArrayList(c);
        ShoppingCartItem si;
        String parm, parmval;
        for (int parmcnt=0; ; parmcnt++) {
          parm="String_Node_Str" + String.valueOf(parmcnt);
          parmval=req.getParameter(parm);
          if ((parmval == null) || parmval.equals("String_Node_Str")) {
            break;
          }
 else {
            int quantity=Integer.parseInt(parmval);
            if (quantity == 0) {
              items.remove(cnt);
            }
 else {
              si=(ShoppingCartItem)items.get(cnt);
              si.setQuantity(quantity);
              items.set(cnt,si);
              cnt++;
            }
          }
        }
        if (items.size() > 0) {
          shoppingCart.setItems(items);
          session.setAttribute(Util.ATTR_CART,shoppingCart);
          session.setAttribute(Util.ATTR_CART_CONTENTS,shoppingCart.getCartContents());
        }
 else {
          session.removeAttribute(Util.ATTR_CART);
          session.removeAttribute(Util.ATTR_CART_CONTENTS);
        }
      }
 catch (      Exception e) {
        Util.debug("String_Node_Str" + e);
        throw new ServletException(e.getMessage());
      }
    }
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_CART);
  }
 else   if (action.equals(ACTION_INITCHECKOUT)) {
    String url;
    HttpSession session=req.getSession(true);
    CustomerInfo customerInfo=(CustomerInfo)session.getAttribute(Util.ATTR_CUSTOMER);
    if (customerInfo == null) {
      req.setAttribute(Util.ATTR_RESULTS,"String_Node_Str");
      session.setAttribute(Util.ATTR_CHECKOUT,new Boolean(true));
      url=Util.PAGE_LOGIN;
    }
 else {
      url=Util.PAGE_ORDERINFO;
    }
    requestDispatch(getServletConfig().getServletContext(),req,resp,url);
  }
 else   if (action.equals(ACTION_ORDERINFODONE)) {
    OrderInfo orderinfo=null;
    ShoppingCart shoppingCart=null;
    HttpSession session=req.getSession(true);
    CustomerInfo customerInfo=(CustomerInfo)session.getAttribute(Util.ATTR_CUSTOMER);
    String customerID=customerInfo.getCustomerID();
    shoppingCart=(ShoppingCart)session.getAttribute(Util.ATTR_CART);
    try {
      Util.debug("String_Node_Str");
      shoppingCart.getItems();
    }
 catch (    RuntimeException e) {
      Util.debug("String_Node_Str");
      ShoppingCartContents cartContents=(ShoppingCartContents)session.getAttribute(Util.ATTR_CART_CONTENTS);
      if (cartContents != null) {
        shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
        shoppingCart.setCartContents(cartContents);
      }
 else {
        Util.debug("String_Node_Str");
        Util.debug("String_Node_Str");
        shoppingCart=null;
      }
    }
    Util.debug("String_Node_Str");
    if (shoppingCart != null) {
      Util.debug("String_Node_Str");
      String billName=req.getParameter("String_Node_Str");
      String billAddr1=req.getParameter("String_Node_Str");
      String billAddr2=req.getParameter("String_Node_Str");
      String billCity=req.getParameter("String_Node_Str");
      String billState=req.getParameter("String_Node_Str");
      String billZip=req.getParameter("String_Node_Str");
      String billPhone=req.getParameter("String_Node_Str");
      String shipName=req.getParameter("String_Node_Str");
      String shipAddr1=req.getParameter("String_Node_Str");
      String shipAddr2=req.getParameter("String_Node_Str");
      String shipCity=req.getParameter("String_Node_Str");
      String shipState=req.getParameter("String_Node_Str");
      String shipZip=req.getParameter("String_Node_Str");
      String shipPhone=req.getParameter("String_Node_Str");
      int shippingMethod=Integer.parseInt(req.getParameter("String_Node_Str"));
      String creditCard=req.getParameter("String_Node_Str");
      String ccNum=req.getParameter("String_Node_Str");
      String ccExpireMonth=req.getParameter("String_Node_Str");
      String ccExpireYear=req.getParameter("String_Node_Str");
      String cardHolder=req.getParameter("String_Node_Str");
      orderinfo=shoppingCart.createOrder(customerID,billName,billAddr1,billAddr2,billCity,billState,billZip,billPhone,shipName,shipAddr1,shipAddr2,shipCity,shipState,shipZip,shipPhone,creditCard,ccNum,ccExpireMonth,ccExpireYear,cardHolder,shippingMethod,shoppingCart.getItems());
      Util.debug("String_Node_Str");
    }
    if (orderinfo != null) {
      req.setAttribute(Util.ATTR_ORDERINFO,orderinfo);
      req.setAttribute(Util.ATTR_CARTITEMS,shoppingCart.getItems());
      session.setAttribute(Util.ATTR_ORDERKEY,orderinfo.getID());
      requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_CHECKOUTFINAL);
    }
  }
 else   if (action.equals(ACTION_COMPLETECHECKOUT)) {
    ShoppingCart shoppingCart=null;
    HttpSession session=req.getSession(true);
    long key=(Long)session.getAttribute(Util.ATTR_ORDERKEY);
    req.setAttribute(Util.ATTR_ORDERID,key);
    long orderKey=key;
    Util.debug("String_Node_Str" + orderKey);
    CustomerInfo customerInfo=(CustomerInfo)session.getAttribute(Util.ATTR_CUSTOMER);
    shoppingCart=(ShoppingCart)session.getAttribute(Util.ATTR_CART);
    try {
      Util.debug("String_Node_Str");
      shoppingCart.getItems();
    }
 catch (    RuntimeException e) {
      Util.debug("String_Node_Str");
      ShoppingCartContents cartContents=(ShoppingCartContents)session.getAttribute(Util.ATTR_CART_CONTENTS);
      if (cartContents != null) {
        shoppingCart=(ShoppingCart)WebUtil.getSpringBean(this.getServletContext(),"String_Node_Str");
        shoppingCart.setCartContents(cartContents);
      }
 else {
        Util.debug("String_Node_Str");
        Util.debug("String_Node_Str");
        shoppingCart=null;
      }
    }
    if (shoppingCart != null) {
      ShoppingCartItem si;
      Collection items=shoppingCart.getItems();
      for (      Object o : items) {
        si=(ShoppingCartItem)o;
        shoppingCart.checkInventory(si);
        Util.debug("String_Node_Str" + si.getID());
      }
    }
    try {
      mailer.createAndSendMail(customerInfo,orderKey);
    }
 catch (    MailerAppException e) {
      System.out.println("String_Node_Str" + e);
      e.printStackTrace();
    }
catch (    Exception e) {
      System.out.println("String_Node_Str" + e);
      e.printStackTrace();
    }
    session.removeAttribute(Util.ATTR_CART);
    session.removeAttribute(Util.ATTR_CART_CONTENTS);
    session.removeAttribute(Util.ATTR_CATEGORY);
    session.removeAttribute(Util.ATTR_ORDERKEY);
    session.removeAttribute(Util.ATTR_CHECKOUT);
    requestDispatch(getServletConfig().getServletContext(),req,resp,Util.PAGE_ORDERDONE);
  }
}