Program: 51993
Project: 51993
Buggy source:
/** 
 * Replace all metadata in item with new passed metadata.
 * @param itemId Id of item in DSpace.
 * @param metadata List of metadata fields, which will replace old metadata in item.
 * @param headers If you want to access to item under logged user into context. In headers must be set header "rest-dspace-token" with passed token from login method.
 * @return It returns status code: OK(200). NOT_FOUND(404) if item was notfound, UNAUTHORIZED(401) if user is not allowed to write to item.
 * @throws WebApplicationException It is thrown by: SQLException, when was problem with database reading or writting, AuthorizeException when was problem with authorization to item and metadata fields. And ContextException, when was problem with creating context of DSpace.
 */
@PUT @Path("String_Node_Str") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Response updateItemMetadata(@PathParam("String_Node_Str") String itemId,MetadataEntry[] metadata,@QueryParam("String_Node_Str") String user_ip,@QueryParam("String_Node_Str") String user_agent,@QueryParam("String_Node_Str") String xforwardedfor,@Context HttpHeaders headers,@Context HttpServletRequest request) throws WebApplicationException {
  log.info("String_Node_Str" + itemId + "String_Node_Str");
  org.dspace.core.Context context=null;
  try {
    context=createContext(getUser(headers));
    org.dspace.content.Item dspaceItem=findItem(context,itemId,org.dspace.core.Constants.WRITE);
    writeStats(dspaceItem,UsageEvent.Action.UPDATE,user_ip,user_agent,xforwardedfor,headers,request,context);
    log.trace("String_Node_Str");
    for (    MetadataEntry entry : metadata) {
      String data[]=mySplit(entry.getKey());
      if ((data.length >= 2) && (data.length <= 3)) {
        itemService.clearMetadata(context,dspaceItem,data[0],data[1],data[2],org.dspace.content.Item.ANY);
      }
    }
    log.trace("String_Node_Str");
    for (    MetadataEntry entry : metadata) {
      String data[]=mySplit(entry.getKey());
      if ((data.length >= 2) && (data.length <= 3)) {
        itemService.addMetadata(context,dspaceItem,data[0],data[1],data[2],entry.getLanguage(),entry.getValue());
      }
    }
    context.complete();
  }
 catch (  SQLException e) {
    processException("String_Node_Str" + itemId + "String_Node_Str"+ e,context);
  }
catch (  ContextException e) {
    processException("String_Node_Str" + itemId + "String_Node_Str"+ e.getMessage(),context);
  }
 finally {
    processFinally(context);
  }
  log.info("String_Node_Str" + itemId + "String_Node_Str");
  return Response.status(Status.OK).build();
}

Fixed version (ground truth):
/** 
 * Replace all metadata in item with new passed metadata.
 * @param itemId Id of item in DSpace.
 * @param metadata List of metadata fields, which will replace old metadata in item.
 * @param headers If you want to access to item under logged user into context. In headers must be set header "rest-dspace-token" with passed token from login method.
 * @return It returns status code: OK(200). NOT_FOUND(404) if item was notfound, UNAUTHORIZED(401) if user is not allowed to write to item.
 * @throws WebApplicationException It is thrown by: SQLException, when was problem with database reading or writting, AuthorizeException when was problem with authorization to item and metadata fields. And ContextException, when was problem with creating context of DSpace.
 */
@PUT @Path("String_Node_Str") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Response updateItemMetadata(@PathParam("String_Node_Str") String itemId,MetadataEntry[] metadata,@QueryParam("String_Node_Str") String user_ip,@QueryParam("String_Node_Str") String user_agent,@QueryParam("String_Node_Str") String xforwardedfor,@Context HttpHeaders headers,@Context HttpServletRequest request) throws WebApplicationException {
  log.info("String_Node_Str" + itemId + "String_Node_Str");
  org.dspace.core.Context context=null;
  try {
    context=createContext(getUser(headers));
    org.dspace.content.Item dspaceItem=findItem(context,itemId,org.dspace.core.Constants.WRITE);
    writeStats(dspaceItem,UsageEvent.Action.UPDATE,user_ip,user_agent,xforwardedfor,headers,request,context);
    log.trace("String_Node_Str");
    for (    MetadataEntry entry : metadata) {
      String data[]=mySplit(entry.getKey());
      if ((data.length >= 2) && (data.length <= 3)) {
        itemService.clearMetadata(context,dspaceItem,data[0],data[1],data[2],org.dspace.content.Item.ANY);
      }
    }
    log.trace("String_Node_Str");
    for (    MetadataEntry entry : metadata) {
      String data[]=mySplit(entry.getKey());
      if ((data.length >= 2) && (data.length <= 3)) {
        itemService.addMetadata(context,dspaceItem,data[0],data[1],data[2],entry.getLanguage(),entry.getValue());
      }
    }
    itemService.update(context,dspaceItem);
    context.complete();
  }
 catch (  SQLException e) {
    processException("String_Node_Str" + itemId + "String_Node_Str"+ e,context);
  }
catch (  ContextException e) {
    processException("String_Node_Str" + itemId + "String_Node_Str"+ e.getMessage(),context);
  }
catch (  AuthorizeException e) {
    processException("String_Node_Str" + itemId + "String_Node_Str"+ e.getMessage(),context);
  }
 finally {
    processFinally(context);
  }
  log.info("String_Node_Str" + itemId + "String_Node_Str");
  return Response.status(Status.OK).build();
}