Program: 3522
Project: 3522
Buggy source:
/** 
 * Create a BrowserScope from the current request
 * @param context The database context
 * @param request The servlet request
 * @param response The servlet response
 * @return A BrowserScope for the current parameters
 * @throws ServletException
 * @throws IOException
 * @throws SQLException
 * @throws AuthorizeException
 */
protected BrowserScope getBrowserScopeForRequest(Context context,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException {
  try {
    String type=request.getParameter("String_Node_Str");
    String order=request.getParameter("String_Node_Str");
    String value=request.getParameter("String_Node_Str");
    String valueLang=request.getParameter("String_Node_Str");
    String month=request.getParameter("String_Node_Str");
    String year=request.getParameter("String_Node_Str");
    String startsWith=request.getParameter("String_Node_Str");
    String valueFocus=request.getParameter("String_Node_Str");
    String valueFocusLang=request.getParameter("String_Node_Str");
    int focus=UIUtil.getIntParameter(request,"String_Node_Str");
    int resultsperpage=UIUtil.getIntParameter(request,"String_Node_Str");
    int sortBy=UIUtil.getIntParameter(request,"String_Node_Str");
    int etAl=UIUtil.getIntParameter(request,"String_Node_Str");
    Collection collection=null;
    Community community=null;
    collection=UIUtil.getCollectionLocation(request);
    if (collection == null) {
      community=UIUtil.getCommunityLocation(request);
    }
    BrowseIndex bi=null;
    if (type != null && !"String_Node_Str".equals(type)) {
      bi=BrowseIndex.getBrowseIndex(type);
    }
    if (bi == null) {
      if (sortBy > 0)       bi=BrowseIndex.getBrowseIndex(SortOption.getSortOption(sortBy));
 else       bi=BrowseIndex.getBrowseIndex(SortOption.getDefaultSortOption());
    }
    if (bi != null && sortBy == -1) {
      SortOption so=bi.getSortOption();
      if (so != null) {
        sortBy=so.getNumber();
      }
    }
 else     if (bi != null && bi.isItemIndex() && !bi.isInternalIndex()) {
      SortOption bso=bi.getSortOption();
      SortOption so=SortOption.getSortOption(sortBy);
      if (bso != null && bso != so) {
        BrowseIndex newBi=BrowseIndex.getBrowseIndex(so);
        if (newBi != null) {
          bi=newBi;
          type=bi.getName();
        }
      }
    }
    if (order == null && bi != null) {
      order=bi.getDefaultOrder();
    }
    if (resultsperpage == -1) {
      resultsperpage=20;
    }
    if (year != null && !"String_Node_Str".equals(year) && !"String_Node_Str".equals(year)) {
      startsWith=year;
      if ((month != null) && !"String_Node_Str".equals(month) && !"String_Node_Str".equals(month)) {
        if ("String_Node_Str".equals(order)) {
          month=Integer.toString((Integer.parseInt(month) - 1));
        }
        if (month.length() == 1) {
          month="String_Node_Str" + month;
        }
        startsWith=year + "String_Node_Str" + month;
      }
    }
    int level=0;
    if (value != null) {
      level=1;
    }
    if (sortBy == -1) {
      sortBy=0;
    }
    if (etAl == -1) {
      int limitLine=ConfigurationManager.getIntProperty("String_Node_Str");
      if (limitLine != 0) {
        etAl=limitLine;
      }
    }
 else {
      if (etAl == 0) {
        etAl=-1;
      }
    }
    String comHandle="String_Node_Str";
    if (community != null) {
      comHandle=community.getHandle();
    }
    String colHandle="String_Node_Str";
    if (collection != null) {
      colHandle=collection.getHandle();
    }
    String arguments="String_Node_Str" + type + "String_Node_Str"+ order+ "String_Node_Str"+ value+ "String_Node_Str"+ month+ "String_Node_Str"+ year+ "String_Node_Str"+ startsWith+ "String_Node_Str"+ valueFocus+ "String_Node_Str"+ focus+ "String_Node_Str"+ resultsperpage+ "String_Node_Str"+ sortBy+ "String_Node_Str"+ comHandle+ "String_Node_Str"+ colHandle+ "String_Node_Str"+ level+ "String_Node_Str"+ etAl;
    log.info(LogManager.getHeader(context,"String_Node_Str",arguments));
    BrowserScope scope=new BrowserScope(context);
    scope.setBrowseIndex(bi);
    scope.setOrder(order);
    scope.setFilterValue(value);
    scope.setFilterValueLang(valueLang);
    scope.setJumpToItem(focus);
    scope.setJumpToValue(valueFocus);
    scope.setJumpToValueLang(valueFocusLang);
    scope.setStartsWith(startsWith);
    scope.setResultsPerPage(resultsperpage);
    scope.setSortBy(sortBy);
    scope.setBrowseLevel(level);
    scope.setEtAl(etAl);
    if (community != null) {
      scope.setBrowseContainer(community);
    }
 else     if (collection != null) {
      scope.setBrowseContainer(collection);
    }
    if (bi.isMetadataIndex() && scope.isSecondLevel() && scope.getSortBy() <= 0) {
      scope.setSortBy(1);
    }
    return scope;
  }
 catch (  SortException se) {
    log.error("String_Node_Str",se);
    throw new ServletException(se);
  }
catch (  BrowseException e) {
    log.error("String_Node_Str",e);
    throw new ServletException(e);
  }
}

Fixed version (ground truth):
/** 
 * Create a BrowserScope from the current request
 * @param context The database context
 * @param request The servlet request
 * @param response The servlet response
 * @return A BrowserScope for the current parameters
 * @throws ServletException
 * @throws IOException
 * @throws SQLException
 * @throws AuthorizeException
 */
protected BrowserScope getBrowserScopeForRequest(Context context,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException {
  try {
    String type=request.getParameter("String_Node_Str");
    String order=request.getParameter("String_Node_Str");
    String value=request.getParameter("String_Node_Str");
    String valueLang=request.getParameter("String_Node_Str");
    String month=request.getParameter("String_Node_Str");
    String year=request.getParameter("String_Node_Str");
    String startsWith=request.getParameter("String_Node_Str");
    String valueFocus=request.getParameter("String_Node_Str");
    String valueFocusLang=request.getParameter("String_Node_Str");
    int focus=UIUtil.getIntParameter(request,"String_Node_Str");
    int resultsperpage=UIUtil.getIntParameter(request,"String_Node_Str");
    int sortBy=UIUtil.getIntParameter(request,"String_Node_Str");
    int etAl=UIUtil.getIntParameter(request,"String_Node_Str");
    Collection collection=null;
    Community community=null;
    collection=UIUtil.getCollectionLocation(request);
    if (collection == null) {
      community=UIUtil.getCommunityLocation(request);
    }
    BrowseIndex bi=null;
    if (type != null && !"String_Node_Str".equals(type)) {
      bi=BrowseIndex.getBrowseIndex(type);
    }
    if (bi == null) {
      if (sortBy > 0)       bi=BrowseIndex.getBrowseIndex(SortOption.getSortOption(sortBy));
 else       bi=BrowseIndex.getBrowseIndex(SortOption.getDefaultSortOption());
    }
    if (bi != null && sortBy == -1) {
      SortOption so=bi.getSortOption();
      if (so != null) {
        sortBy=so.getNumber();
      }
    }
 else     if (bi != null && bi.isItemIndex() && !bi.isInternalIndex()) {
      SortOption bso=bi.getSortOption();
      SortOption so=SortOption.getSortOption(sortBy);
      if (bso != null && bso != so) {
        BrowseIndex newBi=BrowseIndex.getBrowseIndex(so);
        if (newBi != null) {
          bi=newBi;
          type=bi.getName();
        }
      }
    }
    if (order == null && bi != null) {
      order=bi.getDefaultOrder();
    }
    if (resultsperpage == -1) {
      resultsperpage=20;
    }
    if (year != null && !"String_Node_Str".equals(year) && !"String_Node_Str".equals(year)) {
      startsWith=year;
      if ((month != null) && !"String_Node_Str".equals(month) && !"String_Node_Str".equals(month)) {
        if ("String_Node_Str".equals(order)) {
          month=Integer.toString((Integer.parseInt(month) - 1));
        }
        if (month.length() == 1) {
          month="String_Node_Str" + month;
        }
        startsWith=year + "String_Node_Str" + month;
      }
    }
    int level=0;
    if (value != null) {
      level=1;
    }
    if (sortBy == -1) {
      sortBy=0;
    }
    if (etAl == -1) {
      int limitLine=ConfigurationManager.getIntProperty("String_Node_Str");
      if (limitLine != 0) {
        etAl=limitLine;
      }
    }
 else {
      if (etAl == 0) {
        etAl=-1;
      }
    }
    String comHandle="String_Node_Str";
    if (community != null) {
      comHandle=community.getHandle();
    }
    String colHandle="String_Node_Str";
    if (collection != null) {
      colHandle=collection.getHandle();
    }
    String arguments="String_Node_Str" + type + "String_Node_Str"+ order+ "String_Node_Str"+ value+ "String_Node_Str"+ month+ "String_Node_Str"+ year+ "String_Node_Str"+ startsWith+ "String_Node_Str"+ valueFocus+ "String_Node_Str"+ focus+ "String_Node_Str"+ resultsperpage+ "String_Node_Str"+ sortBy+ "String_Node_Str"+ comHandle+ "String_Node_Str"+ colHandle+ "String_Node_Str"+ level+ "String_Node_Str"+ etAl;
    log.info(LogManager.getHeader(context,"String_Node_Str",arguments));
    BrowserScope scope=new BrowserScope(context);
    scope.setBrowseIndex(bi);
    scope.setOrder(order);
    scope.setFilterValue(value);
    scope.setFilterValueLang(valueLang);
    scope.setJumpToItem(focus);
    scope.setJumpToValue(valueFocus);
    scope.setJumpToValueLang(valueFocusLang);
    scope.setStartsWith(startsWith);
    scope.setResultsPerPage(resultsperpage);
    scope.setSortBy(sortBy);
    scope.setBrowseLevel(level);
    scope.setEtAl(etAl);
    if (community != null) {
      scope.setBrowseContainer(community);
    }
 else     if (collection != null) {
      scope.setBrowseContainer(collection);
    }
    if (bi != null && bi.isMetadataIndex() && scope.isSecondLevel() && scope.getSortBy() <= 0) {
      scope.setSortBy(1);
    }
    return scope;
  }
 catch (  SortException se) {
    log.error("String_Node_Str",se);
    throw new ServletException(se);
  }
catch (  BrowseException e) {
    log.error("String_Node_Str",e);
    throw new ServletException(e);
  }
}