Program: 52058
Project: 52058
Buggy source:
/** 
 * Delete subcommunity in community.
 * @param parentCommunityId Id of community in DSpace.
 * @param subcommunityId Id of community which will be deleted.
 * @param headers If you want to access to community under logged user into context. In headers must be set header "rest-dspace-token" with passed token from login method.
 * @return Return response code OK(200) if was everything all right.Otherwise return NOT_FOUND(404) if was id of community or subcommunity incorrect. Or (UNAUTHORIZED)401 if was problem with permission to community or subcommunity.
 * @throws WebApplicationException It is throw when was problem with creating context or problem with database reading or deleting. Or problem with deleting subcommunity caused by IOException or authorization.
 */
@DELETE @Path("String_Node_Str") public Response deleteCommunityCommunity(@PathParam("String_Node_Str") Integer parentCommunityId,@PathParam("String_Node_Str") Integer subcommunityId,@QueryParam("String_Node_Str") String user_ip,@QueryParam("String_Node_Str") String user_agent,@QueryParam("String_Node_Str") String xforwarderfor,@Context HttpHeaders headers,@Context HttpServletRequest request) throws WebApplicationException {
  log.info("String_Node_Str" + parentCommunityId + "String_Node_Str");
  org.dspace.core.Context context=null;
  try {
    context=createContext(getUser(headers));
    org.dspace.content.Community parentCommunity=findCommunity(context,parentCommunityId,org.dspace.core.Constants.WRITE);
    org.dspace.content.Community subcommunity=null;
    for (    org.dspace.content.Community dspaceCommunity : parentCommunity.getSubcommunities()) {
      if (dspaceCommunity.getID() == subcommunityId) {
        subcommunity=dspaceCommunity;
        break;
      }
    }
    if (subcommunity == null) {
      context.abort();
      log.warn("String_Node_Str" + subcommunityId + "String_Node_Str"+ "String_Node_Str");
      throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
 else     if (!AuthorizeManager.authorizeActionBoolean(context,subcommunity,org.dspace.core.Constants.REMOVE)) {
      context.abort();
      if (context.getCurrentUser() != null) {
        log.error("String_Node_Str" + context.getCurrentUser().getEmail() + "String_Node_Str");
      }
 else {
        log.error("String_Node_Str");
      }
      throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
    writeStats(parentCommunity,UsageEvent.Action.UPDATE,user_ip,user_agent,xforwarderfor,headers,request);
    writeStats(subcommunity,UsageEvent.Action.DELETE,user_ip,user_agent,xforwarderfor,headers,request);
    parentCommunity.removeSubcommunity(subcommunity);
    context.complete();
  }
 catch (  SQLException e) {
    processException("String_Node_Str" + subcommunityId + "String_Node_Str"+ parentCommunityId+ "String_Node_Str"+ e,context);
  }
catch (  AuthorizeException e) {
    processException("String_Node_Str" + subcommunityId + "String_Node_Str"+ parentCommunityId+ "String_Node_Str"+ e,context);
  }
catch (  IOException e) {
    processException("String_Node_Str" + subcommunityId + "String_Node_Str"+ parentCommunityId+ "String_Node_Str"+ e,context);
  }
catch (  ContextException e) {
    processException("String_Node_Str" + subcommunityId + "String_Node_Str"+ parentCommunityId+ "String_Node_Str"+ e.getMessage(),context);
  }
 finally {
    processFinally(context);
  }
  log.info("String_Node_Str" + subcommunityId + "String_Node_Str"+ parentCommunityId+ "String_Node_Str");
  return Response.status(Response.Status.OK).build();
}

Fixed version (ground truth):
/** 
 * Delete subcommunity in community.
 * @param parentCommunityId Id of community in DSpace.
 * @param subcommunityId Id of community which will be deleted.
 * @param headers If you want to access to community under logged user into context. In headers must be set header "rest-dspace-token" with passed token from login method.
 * @return Return response code OK(200) if was everything all right.Otherwise return NOT_FOUND(404) if was id of community or subcommunity incorrect. Or (UNAUTHORIZED)401 if was problem with permission to community or subcommunity.
 * @throws WebApplicationException It is throw when was problem with creating context or problem with database reading or deleting. Or problem with deleting subcommunity caused by IOException or authorization.
 */
@DELETE @Path("String_Node_Str") public Response deleteCommunityCommunity(@PathParam("String_Node_Str") Integer parentCommunityId,@PathParam("String_Node_Str") Integer subcommunityId,@QueryParam("String_Node_Str") String user_ip,@QueryParam("String_Node_Str") String user_agent,@QueryParam("String_Node_Str") String xforwarderfor,@Context HttpHeaders headers,@Context HttpServletRequest request) throws WebApplicationException {
  log.info("String_Node_Str" + parentCommunityId + "String_Node_Str");
  org.dspace.core.Context context=null;
  try {
    context=createContext(getUser(headers));
    org.dspace.content.Community parentCommunity=findCommunity(context,parentCommunityId,org.dspace.core.Constants.WRITE);
    org.dspace.content.Community subcommunity=null;
    for (    org.dspace.content.Community dspaceCommunity : parentCommunity.getSubcommunities()) {
      if (dspaceCommunity.getID() == subcommunityId) {
        subcommunity=dspaceCommunity;
        break;
      }
    }
    if (subcommunity == null) {
      context.abort();
      log.warn("String_Node_Str" + subcommunityId + "String_Node_Str"+ "String_Node_Str");
      throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
 else     if (!AuthorizeManager.authorizeActionBoolean(context,subcommunity,org.dspace.core.Constants.REMOVE)) {
      context.abort();
      if (context.getCurrentUser() != null) {
        log.error("String_Node_Str" + context.getCurrentUser().getEmail() + "String_Node_Str");
      }
 else {
        log.error("String_Node_Str");
      }
      throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
    writeStats(parentCommunity,UsageEvent.Action.UPDATE,user_ip,user_agent,xforwarderfor,headers,request,context);
    writeStats(subcommunity,UsageEvent.Action.DELETE,user_ip,user_agent,xforwarderfor,headers,request,context);
    parentCommunity.removeSubcommunity(subcommunity);
    context.complete();
  }
 catch (  SQLException e) {
    processException("String_Node_Str" + subcommunityId + "String_Node_Str"+ parentCommunityId+ "String_Node_Str"+ e,context);
  }
catch (  AuthorizeException e) {
    processException("String_Node_Str" + subcommunityId + "String_Node_Str"+ parentCommunityId+ "String_Node_Str"+ e,context);
  }
catch (  IOException e) {
    processException("String_Node_Str" + subcommunityId + "String_Node_Str"+ parentCommunityId+ "String_Node_Str"+ e,context);
  }
catch (  ContextException e) {
    processException("String_Node_Str" + subcommunityId + "String_Node_Str"+ parentCommunityId+ "String_Node_Str"+ e.getMessage(),context);
  }
 finally {
    processFinally(context);
  }
  log.info("String_Node_Str" + subcommunityId + "String_Node_Str"+ parentCommunityId+ "String_Node_Str");
  return Response.status(Response.Status.OK).build();
}