Program: 51971
Project: 51971
Buggy source:
/** 
 * Find items by one metadata field.
 * @param metadataEntry Metadata field to search by.
 * @param headers If you want to access the item as the user logged into context, header "rest-dspace-token" must be set to token value retrieved from the login method.
 * @return Return array of found items.
 * @throws WebApplicationException Can be thrown: SQLException - problem with database reading. AuthorizeException - problem with authorization to item. IOException - problem with reading from metadata field. ContextException - problem with creating DSpace context.
 */
@POST @Path("String_Node_Str") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Item[] findItemsByMetadataField(MetadataEntry metadataEntry,@QueryParam("String_Node_Str") String expand,@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" + metadataEntry.getKey() + "String_Node_Str"+ metadataEntry.getValue()+ "String_Node_Str"+ metadataEntry.getLanguage()+ "String_Node_Str");
  org.dspace.core.Context context=null;
  List<Item> items=new ArrayList<Item>();
  String[] metadata=mySplit(metadataEntry.getKey());
  if ((metadata.length < 2) || (metadata.length > 3)) {
    context.abort();
    log.error("String_Node_Str");
    throw new WebApplicationException(Response.Status.NOT_FOUND);
  }
  try {
    context=createContext(getUser(headers));
    Iterator<org.dspace.content.Item> itemIterator=itemService.findByMetadataField(context,metadataEntry.getSchema(),metadataEntry.getElement(),metadataEntry.getQualifier(),metadataEntry.getValue());
    while (itemIterator.hasNext()) {
      org.dspace.content.Item dspaceItem=itemIterator.next();
      Item item=new Item(dspaceItem,"String_Node_Str",context);
      writeStats(dspaceItem,UsageEvent.Action.VIEW,user_ip,user_agent,xforwardedfor,headers,request,context);
      items.add(item);
    }
    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);
  }
catch (  IOException e) {
    processException("String_Node_Str" + e.getMessage(),context);
  }
 finally {
    processFinally(context);
  }
  if (items.size() == 0) {
    log.info("String_Node_Str");
  }
 else {
    log.info("String_Node_Str");
  }
  return items.toArray(new Item[0]);
}

Fixed version (ground truth):
/** 
 * Find items by one metadata field.
 * @param metadataEntry Metadata field to search by.
 * @param headers If you want to access the item as the user logged into context, header "rest-dspace-token" must be set to token value retrieved from the login method.
 * @return Return array of found items.
 * @throws WebApplicationException Can be thrown: SQLException - problem with database reading. AuthorizeException - problem with authorization to item. IOException - problem with reading from metadata field. ContextException - problem with creating DSpace context.
 */
@POST @Path("String_Node_Str") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Item[] findItemsByMetadataField(MetadataEntry metadataEntry,@QueryParam("String_Node_Str") String expand,@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" + metadataEntry.getKey() + "String_Node_Str"+ metadataEntry.getValue()+ "String_Node_Str"+ metadataEntry.getLanguage()+ "String_Node_Str");
  org.dspace.core.Context context=null;
  List<Item> items=new ArrayList<Item>();
  String[] metadata=mySplit(metadataEntry.getKey());
  if ((metadata.length < 2) || (metadata.length > 3)) {
    log.error("String_Node_Str");
    throw new WebApplicationException(Response.Status.NOT_FOUND);
  }
  try {
    context=createContext(getUser(headers));
    Iterator<org.dspace.content.Item> itemIterator=itemService.findByMetadataField(context,metadataEntry.getSchema(),metadataEntry.getElement(),metadataEntry.getQualifier(),metadataEntry.getValue());
    while (itemIterator.hasNext()) {
      org.dspace.content.Item dspaceItem=itemIterator.next();
      Item item=new Item(dspaceItem,"String_Node_Str",context);
      writeStats(dspaceItem,UsageEvent.Action.VIEW,user_ip,user_agent,xforwardedfor,headers,request,context);
      items.add(item);
    }
    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);
  }
catch (  IOException e) {
    processException("String_Node_Str" + e.getMessage(),context);
  }
 finally {
    processFinally(context);
  }
  if (items.size() == 0) {
    log.info("String_Node_Str");
  }
 else {
    log.info("String_Node_Str");
  }
  return items.toArray(new Item[0]);
}