Program: 102557
Project: 102557
Buggy source:
/** 
 * Get the comments on an activity.
 * @param uriInfo The uri request uri
 * @param portalContainerName The associated portal container name.
 * @param activityId The specified activity ID.
 * @param format The expected returned format.
 * @anchor SOCref.DevelopersReferences.RestService_APIs_v1alpha3.ActivityResource.Activitycomments.Get
 * @authentication
 * @request {code} GET: http://cloud-workspaces.com/rest/private/api/social/v1-alpha3/portal/activity/1a2b3c4d5e/comments.json {code}
 * @response {code:json} { total: 10, comments: [ { "id": "123456" "identityId": "12345abcde", "text": "Comment there!", "postedTime": 123456789, "createdAt": "Fri Jun 17 06:42:26 +0000 2011" }, { "id" : "234567" "identityId": "12345abcde", "text": "Comment there 2!", "postedTime": 123456789, "createdAt": "Fri Jun 17 06:42:26 +0000 2011" } ] } {code}
 * @return a response object
 */
@GET @Path("String_Node_Str") @Produces(MediaType.APPLICATION_JSON) public Response getCommentsByActivityById(@Context UriInfo uriInfo,@PathParam("String_Node_Str") String portalContainerName,@PathParam("String_Node_Str") String activityId,@PathParam("String_Node_Str") String format){
  RestChecker.checkAuthenticatedRequest();
  PortalContainer portalContainer=RestChecker.checkValidPortalContainerName(portalContainerName);
  MediaType mediaType=RestChecker.checkSupportedFormat(format,SUPPORTED_FORMAT);
  Identity authenticatedIdentity=Util.getAuthenticatedUserIdentity(portalContainerName);
  ActivityManager activityManager=Util.getActivityManager(portalContainerName);
  ExoSocialActivity activity=null;
  try {
    activity=activityManager.getActivity(activityId);
    if (!SecurityManager.canAccessActivity(portalContainer,authenticatedIdentity,activity)) {
      throw new WebApplicationException(Response.Status.FORBIDDEN);
    }
    int total;
    List<CommentRestOut> commentWrapers=null;
    ListAccess<ExoSocialActivity> comments=activityManager.getCommentsWithListAccess(activity);
    total=comments.getSize();
    ExoSocialActivity[] commentsLimited=comments.load(0,total);
    commentWrapers=new ArrayList<CommentRestOut>(total);
    for (int i=0; i < total; i++) {
      CommentRestOut commentRestOut=new CommentRestOut(commentsLimited[i],portalContainerName);
      commentRestOut.setPosterIdentity(commentsLimited[i],portalContainerName);
      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):
/** 
 * Get the comments on an activity.
 * @param uriInfo The uri request uri
 * @param portalContainerName The associated portal container name.
 * @param activityId The specified activity Id.
 * @param format The expected returned format.
 * @anchor SOCref.DevelopersReferences.RestService_APIs_v1alpha3.ActivityResource.Activitycomments.Get
 * @authentication
 * @request {code} GET: http://cloud-workspaces.com/rest/private/api/social/v1-alpha3/portal/activity/1a2b3c4d5e/comments.json {code}
 * @response {code:json} { total: 10, comments: [ { "id": "123456" "identityId": "12345abcde", "text": "Comment there!", "postedTime": 123456789, "createdAt": "Fri Jun 17 06:42:26 +0000 2011" }, { "id" : "234567" "identityId": "12345abcde", "text": "Comment there 2!", "postedTime": 123456789, "createdAt": "Fri Jun 17 06:42:26 +0000 2011" } ] } {code}
 * @return a response object
 */
@GET @Path("String_Node_Str") @Produces(MediaType.APPLICATION_JSON) public Response getCommentsByActivityById(@Context UriInfo uriInfo,@PathParam("String_Node_Str") String portalContainerName,@PathParam("String_Node_Str") String activityId,@PathParam("String_Node_Str") String format){
  RestChecker.checkAuthenticatedRequest();
  PortalContainer portalContainer=RestChecker.checkValidPortalContainerName(portalContainerName);
  MediaType mediaType=RestChecker.checkSupportedFormat(format,SUPPORTED_FORMAT);
  Identity authenticatedIdentity=Util.getAuthenticatedUserIdentity(portalContainerName);
  ActivityManager activityManager=Util.getActivityManager(portalContainerName);
  ExoSocialActivity activity=null;
  try {
    activity=activityManager.getActivity(activityId);
    if (!SecurityManager.canAccessActivity(portalContainer,authenticatedIdentity,activity)) {
      throw new WebApplicationException(Response.Status.FORBIDDEN);
    }
    int total;
    List<CommentRestOut> commentWrapers=null;
    ListAccess<ExoSocialActivity> comments=activityManager.getCommentsWithListAccess(activity);
    total=comments.getSize();
    ExoSocialActivity[] commentsLimited=comments.load(0,total);
    commentWrapers=new ArrayList<CommentRestOut>(total);
    for (int i=0; i < total; i++) {
      CommentRestOut commentRestOut=new CommentRestOut(commentsLimited[i],portalContainerName);
      commentRestOut.setPosterIdentity(commentsLimited[i],portalContainerName);
      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);
  }
}