Program: 52059
Project: 52059
Buggy source:
/** 
 * Create community at top level. Creating community at top level has permission only admin.
 * @param community Community which will be created at top level of communities.
 * @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 Returns response with handle of community, if was all ok.
 * @throws WebApplicationException It can be thrown by SQLException, AuthorizeException and ContextException.
 */
@POST @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Community createCommunity(Community community,@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");
  org.dspace.core.Context context=null;
  Community retCommunity=null;
  try {
    context=createContext(getUser(headers));
    if (!AuthorizeManager.isAdmin(context)) {
      context.abort();
      String user="String_Node_Str";
      if (context.getCurrentUser() != null) {
        user=context.getCurrentUser().getEmail();
      }
      log.error("String_Node_Str" + user + "String_Node_Str");
      throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
    org.dspace.content.Community dspaceCommunity=org.dspace.content.Community.create(null,context);
    writeStats(dspaceCommunity,UsageEvent.Action.CREATE,user_ip,user_agent,xforwarderfor,headers,request);
    dspaceCommunity.setMetadata("String_Node_Str",community.getName());
    dspaceCommunity.setMetadata(org.dspace.content.Community.COPYRIGHT_TEXT,community.getCopyrightText());
    dspaceCommunity.setMetadata(org.dspace.content.Community.INTRODUCTORY_TEXT,community.getIntroductoryText());
    dspaceCommunity.setMetadata(org.dspace.content.Community.SHORT_DESCRIPTION,community.getShortDescription());
    dspaceCommunity.setMetadata(org.dspace.content.Community.SIDEBAR_TEXT,community.getSidebarText());
    dspaceCommunity.update();
    retCommunity=new Community(dspaceCommunity,"String_Node_Str",context);
    context.complete();
  }
 catch (  SQLException e) {
    processException("String_Node_Str" + e,context);
  }
catch (  ContextException e) {
    processException("String_Node_Str" + e.getMessage(),context);
  }
catch (  AuthorizeException e) {
    processException("String_Node_Str" + e.getMessage(),context);
  }
 finally {
    processFinally(context);
  }
  log.info("String_Node_Str" + retCommunity.getHandle());
  return retCommunity;
}

Fixed version (ground truth):
/** 
 * Create community at top level. Creating community at top level has permission only admin.
 * @param community Community which will be created at top level of communities.
 * @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 Returns response with handle of community, if was all ok.
 * @throws WebApplicationException It can be thrown by SQLException, AuthorizeException and ContextException.
 */
@POST @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Community createCommunity(Community community,@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");
  org.dspace.core.Context context=null;
  Community retCommunity=null;
  try {
    context=createContext(getUser(headers));
    if (!AuthorizeManager.isAdmin(context)) {
      context.abort();
      String user="String_Node_Str";
      if (context.getCurrentUser() != null) {
        user=context.getCurrentUser().getEmail();
      }
      log.error("String_Node_Str" + user + "String_Node_Str");
      throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
    org.dspace.content.Community dspaceCommunity=org.dspace.content.Community.create(null,context);
    writeStats(dspaceCommunity,UsageEvent.Action.CREATE,user_ip,user_agent,xforwarderfor,headers,request,context);
    dspaceCommunity.setMetadata("String_Node_Str",community.getName());
    dspaceCommunity.setMetadata(org.dspace.content.Community.COPYRIGHT_TEXT,community.getCopyrightText());
    dspaceCommunity.setMetadata(org.dspace.content.Community.INTRODUCTORY_TEXT,community.getIntroductoryText());
    dspaceCommunity.setMetadata(org.dspace.content.Community.SHORT_DESCRIPTION,community.getShortDescription());
    dspaceCommunity.setMetadata(org.dspace.content.Community.SIDEBAR_TEXT,community.getSidebarText());
    dspaceCommunity.update();
    retCommunity=new Community(dspaceCommunity,"String_Node_Str",context);
    context.complete();
  }
 catch (  SQLException e) {
    processException("String_Node_Str" + e,context);
  }
catch (  ContextException e) {
    processException("String_Node_Str" + e.getMessage(),context);
  }
catch (  AuthorizeException e) {
    processException("String_Node_Str" + e.getMessage(),context);
  }
 finally {
    processFinally(context);
  }
  log.info("String_Node_Str" + retCommunity.getHandle());
  return retCommunity;
}