Program: 102538
Project: 102538
Buggy source:
/** 
 * Show comment list by json/xml format with limit and offset.
 * @param uriInfo
 * @param activityId
 * @param format
 * @param offset
 * @param limit
 * @return response
 * @throws Exception
 */
@GET @Path("String_Node_Str") public Response showComments(@Context UriInfo uriInfo,@PathParam("String_Node_Str") String portalName,@PathParam("String_Node_Str") String activityId,@PathParam("String_Node_Str") String format,@QueryParam("String_Node_Str") Integer offset,@QueryParam("String_Node_Str") Integer limit) throws Exception {
  PortalContainer portalContainer=RestChecker.checkValidPortalContainerName(portalName);
  MediaType mediaType=RestChecker.checkSupportedFormat(format,new String[]{"String_Node_Str"});
  ActivityManager activityManager=Util.getActivityManager(portalName);
  if (offset == null || limit == null) {
    offset=0;
    limit=10;
  }
  if (offset < 0 || limit < 0) {
    throw new WebApplicationException(Response.Status.BAD_REQUEST);
  }
  ExoSocialActivity activity=null;
  try {
    activity=activityManager.getActivity(activityId);
    int total;
    List<CommentRestOut> commentWrapers=null;
    ListAccess<ExoSocialActivity> comments=activityManager.getCommentsWithListAccess(activity);
    if (offset > comments.getSize()) {
      offset=0;
      limit=0;
    }
 else     if (offset + limit > comments.getSize()) {
      limit=comments.getSize() - offset;
    }
    total=limit;
    ExoSocialActivity[] commentsLimited=comments.load(offset,total + offset);
    commentWrapers=new ArrayList<CommentRestOut>(total);
    for (int i=0; i < total; i++) {
      CommentRestOut commentRestOut=new CommentRestOut(commentsLimited[i],portalName);
      commentRestOut.setPosterIdentity(commentsLimited[i],portalName);
      commentWrapers.add(commentRestOut);
    }
    HashMap<String,Object> resultJson=new HashMap<String,Object>();
    resultJson.put("String_Node_Str",commentWrapers.size());
    resultJson.put("String_Node_Str",commentWrapers);
    return Util.getResponse(resultJson,uriInfo,mediaType,Response.Status.OK);
  }
 catch (  UndeclaredThrowableException undeclaredThrowableException) {
    if (undeclaredThrowableException.getCause() instanceof ActivityStorageException) {
      throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
 else {
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
  }
catch (  Exception e) {
    throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
  }
}

Fixed version (ground truth):
/** 
 * Show comment list by the JSON/XML format with limit and offset.
 * @param uriInfo
 * @param activityId
 * @param format
 * @param offset
 * @param limit
 * @return response
 * @throws Exception
 */
@GET @Path("String_Node_Str") public Response showComments(@Context UriInfo uriInfo,@PathParam("String_Node_Str") String portalName,@PathParam("String_Node_Str") String activityId,@PathParam("String_Node_Str") String format,@QueryParam("String_Node_Str") Integer offset,@QueryParam("String_Node_Str") Integer limit) throws Exception {
  PortalContainer portalContainer=RestChecker.checkValidPortalContainerName(portalName);
  MediaType mediaType=RestChecker.checkSupportedFormat(format,new String[]{"String_Node_Str"});
  ActivityManager activityManager=Util.getActivityManager(portalName);
  if (offset == null || limit == null) {
    offset=0;
    limit=10;
  }
  if (offset < 0 || limit < 0) {
    throw new WebApplicationException(Response.Status.BAD_REQUEST);
  }
  ExoSocialActivity activity=null;
  try {
    activity=activityManager.getActivity(activityId);
    int total;
    List<CommentRestOut> commentWrapers=null;
    ListAccess<ExoSocialActivity> comments=activityManager.getCommentsWithListAccess(activity);
    if (offset > comments.getSize()) {
      offset=0;
      limit=0;
    }
 else     if (offset + limit > comments.getSize()) {
      limit=comments.getSize() - offset;
    }
    total=limit;
    ExoSocialActivity[] commentsLimited=comments.load(offset,total + offset);
    commentWrapers=new ArrayList<CommentRestOut>(total);
    for (int i=0; i < total; i++) {
      CommentRestOut commentRestOut=new CommentRestOut(commentsLimited[i],portalName);
      commentRestOut.setPosterIdentity(commentsLimited[i],portalName);
      commentWrapers.add(commentRestOut);
    }
    HashMap<String,Object> resultJson=new HashMap<String,Object>();
    resultJson.put("String_Node_Str",commentWrapers.size());
    resultJson.put("String_Node_Str",commentWrapers);
    return Util.getResponse(resultJson,uriInfo,mediaType,Response.Status.OK);
  }
 catch (  UndeclaredThrowableException undeclaredThrowableException) {
    if (undeclaredThrowableException.getCause() instanceof ActivityStorageException) {
      throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
 else {
      throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
  }
catch (  Exception e) {
    throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
  }
}