Program: 52060
Project: 52060
Buggy source:
/** 
 * Create collection in community.
 * @param communityId Id of community in DSpace.
 * @param collection Collection which will be added into community.
 * @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 200 if was everything all right. Otherwise 400when id of community was incorrect or 401 if was problem with permission to write into collection.
 * @throws WebApplicationException It is thrown when was problem with database reading or writing. Or problem with authorization to community. Or problem with creating context.
 */
@POST @Path("String_Node_Str") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Collection addCommunityCollection(@PathParam("String_Node_Str") Integer communityId,Collection collection,@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" + communityId + "String_Node_Str");
  org.dspace.core.Context context=null;
  Collection retCollection=null;
  try {
    context=createContext(getUser(headers));
    org.dspace.content.Community dspaceCommunity=findCommunity(context,communityId,org.dspace.core.Constants.WRITE);
    writeStats(dspaceCommunity,UsageEvent.Action.UPDATE,user_ip,user_agent,xforwarderfor,headers,request);
    org.dspace.content.Collection dspaceCollection=dspaceCommunity.createCollection();
    dspaceCollection.setLicense(collection.getLicense());
    dspaceCollection.setMetadata("String_Node_Str",collection.getName());
    dspaceCollection.setMetadata(org.dspace.content.Collection.COPYRIGHT_TEXT,collection.getCopyrightText());
    dspaceCollection.setMetadata(org.dspace.content.Collection.INTRODUCTORY_TEXT,collection.getIntroductoryText());
    dspaceCollection.setMetadata(org.dspace.content.Collection.SHORT_DESCRIPTION,collection.getShortDescription());
    dspaceCollection.setMetadata(org.dspace.content.Collection.SIDEBAR_TEXT,collection.getSidebarText());
    dspaceCollection.setLicense(collection.getLicense());
    dspaceCollection.update();
    dspaceCommunity.update();
    retCollection=new Collection(dspaceCollection,"String_Node_Str",context,100,0);
    context.complete();
  }
 catch (  SQLException e) {
    processException("String_Node_Str" + communityId + "String_Node_Str"+ e,context);
  }
catch (  AuthorizeException e) {
    processException("String_Node_Str" + communityId + "String_Node_Str"+ e,context);
  }
catch (  ContextException e) {
    processException("String_Node_Str" + communityId + "String_Node_Str"+ e.getMessage(),context);
  }
 finally {
    processFinally(context);
  }
  log.info("String_Node_Str" + communityId + "String_Node_Str"+ retCollection.getHandle());
  return retCollection;
}

Fixed version (ground truth):
/** 
 * Create collection in community.
 * @param communityId Id of community in DSpace.
 * @param collection Collection which will be added into community.
 * @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 200 if was everything all right. Otherwise 400when id of community was incorrect or 401 if was problem with permission to write into collection.
 * @throws WebApplicationException It is thrown when was problem with database reading or writing. Or problem with authorization to community. Or problem with creating context.
 */
@POST @Path("String_Node_Str") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Collection addCommunityCollection(@PathParam("String_Node_Str") Integer communityId,Collection collection,@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" + communityId + "String_Node_Str");
  org.dspace.core.Context context=null;
  Collection retCollection=null;
  try {
    context=createContext(getUser(headers));
    org.dspace.content.Community dspaceCommunity=findCommunity(context,communityId,org.dspace.core.Constants.WRITE);
    writeStats(dspaceCommunity,UsageEvent.Action.UPDATE,user_ip,user_agent,xforwarderfor,headers,request,context);
    org.dspace.content.Collection dspaceCollection=dspaceCommunity.createCollection();
    dspaceCollection.setLicense(collection.getLicense());
    dspaceCollection.setMetadata("String_Node_Str",collection.getName());
    dspaceCollection.setMetadata(org.dspace.content.Collection.COPYRIGHT_TEXT,collection.getCopyrightText());
    dspaceCollection.setMetadata(org.dspace.content.Collection.INTRODUCTORY_TEXT,collection.getIntroductoryText());
    dspaceCollection.setMetadata(org.dspace.content.Collection.SHORT_DESCRIPTION,collection.getShortDescription());
    dspaceCollection.setMetadata(org.dspace.content.Collection.SIDEBAR_TEXT,collection.getSidebarText());
    dspaceCollection.setLicense(collection.getLicense());
    dspaceCollection.update();
    dspaceCommunity.update();
    retCollection=new Collection(dspaceCollection,"String_Node_Str",context,100,0);
    context.complete();
  }
 catch (  SQLException e) {
    processException("String_Node_Str" + communityId + "String_Node_Str"+ e,context);
  }
catch (  AuthorizeException e) {
    processException("String_Node_Str" + communityId + "String_Node_Str"+ e,context);
  }
catch (  ContextException e) {
    processException("String_Node_Str" + communityId + "String_Node_Str"+ e.getMessage(),context);
  }
 finally {
    processFinally(context);
  }
  log.info("String_Node_Str" + communityId + "String_Node_Str"+ retCollection.getHandle());
  return retCollection;
}