Program: 52561
Project: 52561
Buggy source:
protected void doDSGet(Context context,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException {
  String query=request.getParameter("String_Node_Str");
  int start=UIUtil.getIntParameter(request,"String_Node_Str");
  String advanced=request.getParameter("String_Node_Str");
  String fromAdvanced=request.getParameter("String_Node_Str");
  String advancedQuery="String_Node_Str";
  HashMap queryHash=new HashMap();
  if (start < 0) {
    start=0;
  }
  List itemHandles=new ArrayList();
  List collectionHandles=new ArrayList();
  List communityHandles=new ArrayList();
  Item[] resultsItems;
  Collection[] resultsCollections;
  Community[] resultsCommunities;
  QueryResults qResults=null;
  QueryArgs qArgs=new QueryArgs();
  if (advanced != null) {
    query=qArgs.buildQuery(request);
    advancedQuery=qArgs.buildHTTPQuery(request);
  }
  if (query == null) {
    query="String_Node_Str";
  }
  String location=request.getParameter("String_Node_Str");
  String newURL;
  if (location != null && !location.equals("String_Node_Str")) {
    String url="String_Node_Str";
    if (!location.equals("String_Node_Str")) {
      url="String_Node_Str" + location;
    }
    query=URLEncoder.encode(query);
    if (advancedQuery.length() > 0) {
      query=query + "String_Node_Str" + advancedQuery;
    }
    response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + url + "String_Node_Str"+ query));
    return;
  }
  String logInfo="String_Node_Str";
  Community community=UIUtil.getCommunityLocation(request);
  Collection collection=UIUtil.getCollectionLocation(request);
  qArgs.setQuery(query);
  qArgs.setStart(start);
  try {
    if (collection != null) {
      logInfo="String_Node_Str" + collection.getID() + "String_Node_Str";
      request.setAttribute("String_Node_Str",community);
      request.setAttribute("String_Node_Str",collection);
      qResults=DSQuery.doQuery(context,qArgs,collection);
    }
 else     if (community != null) {
      logInfo="String_Node_Str" + community.getID() + "String_Node_Str";
      request.setAttribute("String_Node_Str",community);
      request.setAttribute("String_Node_Str",community.getCollections());
      qResults=DSQuery.doQuery(context,qArgs,community);
    }
 else {
      Community[] communities=Community.findAll(context);
      request.setAttribute("String_Node_Str",communities);
      qResults=DSQuery.doQuery(context,qArgs);
    }
    for (int i=0; i < qResults.getHitHandles().size(); i++) {
      String myHandle=(String)qResults.getHitHandles().get(i);
      Integer myType=(Integer)qResults.getHitTypes().get(i);
switch (myType.intValue()) {
case Constants.ITEM:
        itemHandles.add(myHandle);
      break;
case Constants.COLLECTION:
    collectionHandles.add(myHandle);
  break;
case Constants.COMMUNITY:
communityHandles.add(myHandle);
break;
}
}
int numCommunities=communityHandles.size();
int numCollections=collectionHandles.size();
int numItems=itemHandles.size();
resultsCommunities=new Community[numCommunities];
resultsCollections=new Collection[numCollections];
resultsItems=new Item[numItems];
for (int i=0; i < numItems; i++) {
String myhandle=(String)itemHandles.get(i);
Object o=HandleManager.resolveToObject(context,myhandle);
resultsItems[i]=(Item)o;
if (resultsItems[i] == null) {
throw new SQLException("String_Node_Str" + query + "String_Node_Str"+ myhandle);
}
}
for (int i=0; i < collectionHandles.size(); i++) {
String myhandle=(String)collectionHandles.get(i);
Object o=HandleManager.resolveToObject(context,myhandle);
resultsCollections[i]=(Collection)o;
if (resultsCollections[i] == null) {
throw new SQLException("String_Node_Str" + query + "String_Node_Str"+ myhandle);
}
}
for (int i=0; i < communityHandles.size(); i++) {
String myhandle=(String)communityHandles.get(i);
Object o=HandleManager.resolveToObject(context,myhandle);
resultsCommunities[i]=(Community)o;
if (resultsCommunities[i] == null) {
throw new SQLException("String_Node_Str" + query + "String_Node_Str"+ myhandle);
}
}
log.info(LogManager.getHeader(context,"String_Node_Str",logInfo + "String_Node_Str" + query+ "String_Node_Str"+ resultsCommunities.length+ "String_Node_Str"+ resultsCollections.length+ "String_Node_Str"+ resultsItems.length+ "String_Node_Str"));
}
 catch (ParseException pe) {
log.warn(LogManager.getHeader(context,"String_Node_Str",logInfo + "String_Node_Str" + query+ "String_Node_Str"),pe);
resultsItems=new Item[0];
resultsCommunities=new Community[0];
resultsCollections=new Collection[0];
}
catch (TokenMgrError tme) {
log.warn(LogManager.getHeader(context,"String_Node_Str",logInfo + "String_Node_Str" + query+ "String_Node_Str"),tme);
resultsItems=new Item[0];
resultsCommunities=new Community[0];
resultsCollections=new Collection[0];
}
int pageTotal=1 + (qResults.getHitCount() - 1) / qResults.getPageSize();
int pageCurrent=1 + (qResults.getStart() / qResults.getPageSize());
int pageLast=(pageCurrent + 9) > pageTotal ? pageTotal : (pageCurrent + 9);
int pageFirst=(pageCurrent - 9) > 1 ? (pageCurrent - 9) : 1;
request.setAttribute("String_Node_Str",resultsItems);
request.setAttribute("String_Node_Str",resultsCommunities);
request.setAttribute("String_Node_Str",resultsCollections);
request.setAttribute("String_Node_Str",new Integer(pageTotal));
request.setAttribute("String_Node_Str",new Integer(pageCurrent));
request.setAttribute("String_Node_Str",new Integer(pageLast));
request.setAttribute("String_Node_Str",new Integer(pageFirst));
request.setAttribute("String_Node_Str",qResults);
request.setAttribute("String_Node_Str",query);
if ((fromAdvanced != null) && (qResults.getHitCount() == 0)) {
Community[] communities=Community.findAll(context);
request.setAttribute("String_Node_Str",communities);
request.setAttribute("String_Node_Str","String_Node_Str");
queryHash=qArgs.buildQueryHash(request);
Iterator i=queryHash.keySet().iterator();
while (i.hasNext()) {
String key=(String)i.next();
String value=(String)queryHash.get(key);
request.setAttribute(key,value);
}
JSPManager.showJSP(request,response,"String_Node_Str");
}
 else {
JSPManager.showJSP(request,response,"String_Node_Str");
}
}

Fixed version (ground truth):
protected void doDSGet(Context context,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException, SQLException, AuthorizeException {
  String query=request.getParameter("String_Node_Str");
  int start=UIUtil.getIntParameter(request,"String_Node_Str");
  String advanced=request.getParameter("String_Node_Str");
  String fromAdvanced=request.getParameter("String_Node_Str");
  String advancedQuery="String_Node_Str";
  HashMap queryHash=new HashMap();
  if (start < 0) {
    start=0;
  }
  List itemHandles=new ArrayList();
  List collectionHandles=new ArrayList();
  List communityHandles=new ArrayList();
  Item[] resultsItems;
  Collection[] resultsCollections;
  Community[] resultsCommunities;
  QueryResults qResults=null;
  QueryArgs qArgs=new QueryArgs();
  if (advanced != null) {
    query=qArgs.buildQuery(request);
    advancedQuery=qArgs.buildHTTPQuery(request);
  }
  if (query == null) {
    query="String_Node_Str";
  }
  String location=request.getParameter("String_Node_Str");
  String newURL;
  if (location != null && !location.equals("String_Node_Str")) {
    String url="String_Node_Str";
    if (!location.equals("String_Node_Str")) {
      url="String_Node_Str" + location;
    }
    query=URLEncoder.encode(query);
    if (advancedQuery.length() > 0) {
      query=query + "String_Node_Str" + advancedQuery;
    }
    response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + url + "String_Node_Str"+ query));
    return;
  }
  String logInfo="String_Node_Str";
  Community community=UIUtil.getCommunityLocation(request);
  Collection collection=UIUtil.getCollectionLocation(request);
  qArgs.setQuery(query);
  qArgs.setStart(start);
  if (collection != null) {
    logInfo="String_Node_Str" + collection.getID() + "String_Node_Str";
    request.setAttribute("String_Node_Str",community);
    request.setAttribute("String_Node_Str",collection);
    qResults=DSQuery.doQuery(context,qArgs,collection);
  }
 else   if (community != null) {
    logInfo="String_Node_Str" + community.getID() + "String_Node_Str";
    request.setAttribute("String_Node_Str",community);
    request.setAttribute("String_Node_Str",community.getCollections());
    qResults=DSQuery.doQuery(context,qArgs,community);
  }
 else {
    Community[] communities=Community.findAll(context);
    request.setAttribute("String_Node_Str",communities);
    qResults=DSQuery.doQuery(context,qArgs);
  }
  for (int i=0; i < qResults.getHitHandles().size(); i++) {
    String myHandle=(String)qResults.getHitHandles().get(i);
    Integer myType=(Integer)qResults.getHitTypes().get(i);
switch (myType.intValue()) {
case Constants.ITEM:
      itemHandles.add(myHandle);
    break;
case Constants.COLLECTION:
  collectionHandles.add(myHandle);
break;
case Constants.COMMUNITY:
communityHandles.add(myHandle);
break;
}
}
int numCommunities=communityHandles.size();
int numCollections=collectionHandles.size();
int numItems=itemHandles.size();
resultsCommunities=new Community[numCommunities];
resultsCollections=new Collection[numCollections];
resultsItems=new Item[numItems];
for (int i=0; i < numItems; i++) {
String myhandle=(String)itemHandles.get(i);
Object o=HandleManager.resolveToObject(context,myhandle);
resultsItems[i]=(Item)o;
if (resultsItems[i] == null) {
throw new SQLException("String_Node_Str" + query + "String_Node_Str"+ myhandle);
}
}
for (int i=0; i < collectionHandles.size(); i++) {
String myhandle=(String)collectionHandles.get(i);
Object o=HandleManager.resolveToObject(context,myhandle);
resultsCollections[i]=(Collection)o;
if (resultsCollections[i] == null) {
throw new SQLException("String_Node_Str" + query + "String_Node_Str"+ myhandle);
}
}
for (int i=0; i < communityHandles.size(); i++) {
String myhandle=(String)communityHandles.get(i);
Object o=HandleManager.resolveToObject(context,myhandle);
resultsCommunities[i]=(Community)o;
if (resultsCommunities[i] == null) {
throw new SQLException("String_Node_Str" + query + "String_Node_Str"+ myhandle);
}
}
log.info(LogManager.getHeader(context,"String_Node_Str",logInfo + "String_Node_Str" + query+ "String_Node_Str"+ resultsCommunities.length+ "String_Node_Str"+ resultsCollections.length+ "String_Node_Str"+ resultsItems.length+ "String_Node_Str"));
int pageTotal=1 + (qResults.getHitCount() - 1) / qResults.getPageSize();
int pageCurrent=1 + (qResults.getStart() / qResults.getPageSize());
int pageLast=(pageCurrent + 9) > pageTotal ? pageTotal : (pageCurrent + 9);
int pageFirst=(pageCurrent - 9) > 1 ? (pageCurrent - 9) : 1;
request.setAttribute("String_Node_Str",resultsItems);
request.setAttribute("String_Node_Str",resultsCommunities);
request.setAttribute("String_Node_Str",resultsCollections);
request.setAttribute("String_Node_Str",new Integer(pageTotal));
request.setAttribute("String_Node_Str",new Integer(pageCurrent));
request.setAttribute("String_Node_Str",new Integer(pageLast));
request.setAttribute("String_Node_Str",new Integer(pageFirst));
request.setAttribute("String_Node_Str",qResults);
request.setAttribute("String_Node_Str",query);
if ((fromAdvanced != null) && (qResults.getHitCount() == 0)) {
Community[] communities=Community.findAll(context);
request.setAttribute("String_Node_Str",communities);
request.setAttribute("String_Node_Str","String_Node_Str");
queryHash=qArgs.buildQueryHash(request);
Iterator i=queryHash.keySet().iterator();
while (i.hasNext()) {
String key=(String)i.next();
String value=(String)queryHash.get(key);
request.setAttribute(key,value);
}
JSPManager.showJSP(request,response,"String_Node_Str");
}
 else {
JSPManager.showJSP(request,response,"String_Node_Str");
}
}