nus-yam/ex-repair huggingface dataset:
Program: 51874
Project: 51874
Buggy source:
@Override public void removeClaimedUser(Context context,XmlWorkflowItem wfi,EPerson user,String stepID) throws SQLException, IOException, WorkflowConfigurationException, AuthorizeException {
  int totalUsers=inProgressUserService.getNumberOfInProgressUsers(context,wfi) + inProgressUserService.getNumberOfFinishedUsers(context,wfi);
  inProgressUserService.delete(context,inProgressUserService.findByWorkflowItemAndEPerson(context,wfi,user));
  Workflow workflow=workflowFactory.getWorkflow(wfi.getCollection());
  Step step=workflow.getStep(stepID);
  if (totalUsers == step.getRequiredUsers()) {
    List<InProgressUser> toIgnore=inProgressUserService.findByWorkflowItem(context,wfi);
    RoleMembers roleMembers=step.getRole().getMembers(context,wfi);
    for (    InProgressUser ipu : toIgnore) {
      roleMembers.removeEperson(ipu.getUser());
    }
    step.getUserSelectionMethod().getProcessingAction().regenerateTasks(context,wfi,roleMembers);
  }
 else {
    RoleMembers role=step.getRole().getMembers(context,wfi);
    List<EPerson> epersons=role.getEPersons();
    for (    EPerson eperson : epersons) {
      if (eperson.getID().equals(user.getID())) {
        RoleMembers memberToRegenerateTasksFor=new RoleMembers();
        memberToRegenerateTasksFor.addEPerson(user);
        step.getUserSelectionMethod().getProcessingAction().regenerateTasks(context,wfi,memberToRegenerateTasksFor);
        break;
      }
    }
  }
  itemService.update(context,wfi.getItem());
}

Fixed version (ground truth):
@Override public void removeClaimedUser(Context context,XmlWorkflowItem wfi,EPerson user,String stepID) throws SQLException, IOException, WorkflowConfigurationException, AuthorizeException {
  int totalUsers=inProgressUserService.getNumberOfInProgressUsers(context,wfi) + inProgressUserService.getNumberOfFinishedUsers(context,wfi);
  inProgressUserService.delete(context,inProgressUserService.findByWorkflowItemAndEPerson(context,wfi,user));
  xmlWorkflowService.removeUserItemPolicies(context,wfi.getItem(),user);
  Workflow workflow=workflowFactory.getWorkflow(wfi.getCollection());
  Step step=workflow.getStep(stepID);
  if (totalUsers == step.getRequiredUsers()) {
    List<InProgressUser> toIgnore=inProgressUserService.findByWorkflowItem(context,wfi);
    RoleMembers roleMembers=step.getRole().getMembers(context,wfi);
    for (    InProgressUser ipu : toIgnore) {
      roleMembers.removeEperson(ipu.getUser());
    }
    step.getUserSelectionMethod().getProcessingAction().regenerateTasks(context,wfi,roleMembers);
  }
 else {
    RoleMembers role=step.getRole().getMembers(context,wfi);
    List<EPerson> epersons=role.getEPersons();
    for (    EPerson eperson : epersons) {
      if (eperson.getID().equals(user.getID())) {
        RoleMembers memberToRegenerateTasksFor=new RoleMembers();
        memberToRegenerateTasksFor.addEPerson(user);
        step.getUserSelectionMethod().getProcessingAction().regenerateTasks(context,wfi,memberToRegenerateTasksFor);
        break;
      }
    }
  }
  itemService.update(context,wfi.getItem());
}
Program: 51875
Project: 51875
Buggy source:
protected void grantUserAllItemPolicies(Context context,Item item,EPerson epa) throws AuthorizeException, SQLException {
  if (epa != null) {
    List<Integer> userHasPolicies=new ArrayList<Integer>();
    List<ResourcePolicy> itempols=authorizeService.getPolicies(context,item);
    for (    ResourcePolicy resourcePolicy : itempols) {
      if (epa.equals(resourcePolicy.getEPerson())) {
        userHasPolicies.add(resourcePolicy.getAction());
      }
    }
    if (!userHasPolicies.contains(Constants.READ))     addPolicyToItem(context,item,Constants.READ,epa);
    if (!userHasPolicies.contains(Constants.WRITE))     addPolicyToItem(context,item,Constants.WRITE,epa);
    if (!userHasPolicies.contains(Constants.DELETE))     addPolicyToItem(context,item,Constants.DELETE,epa);
    if (!userHasPolicies.contains(Constants.ADD))     addPolicyToItem(context,item,Constants.ADD,epa);
    if (!userHasPolicies.contains(Constants.REMOVE))     addPolicyToItem(context,item,Constants.REMOVE,epa);
  }
}

Fixed version (ground truth):
public void grantUserAllItemPolicies(Context context,Item item,EPerson epa) throws AuthorizeException, SQLException {
  if (epa != null) {
    List<Integer> userHasPolicies=new ArrayList<Integer>();
    List<ResourcePolicy> itempols=authorizeService.getPolicies(context,item);
    for (    ResourcePolicy resourcePolicy : itempols) {
      if (epa.equals(resourcePolicy.getEPerson())) {
        userHasPolicies.add(resourcePolicy.getAction());
      }
    }
    if (!userHasPolicies.contains(Constants.READ))     addPolicyToItem(context,item,Constants.READ,epa);
    if (!userHasPolicies.contains(Constants.WRITE))     addPolicyToItem(context,item,Constants.WRITE,epa);
    if (!userHasPolicies.contains(Constants.DELETE))     addPolicyToItem(context,item,Constants.DELETE,epa);
    if (!userHasPolicies.contains(Constants.ADD))     addPolicyToItem(context,item,Constants.ADD,epa);
    if (!userHasPolicies.contains(Constants.REMOVE))     addPolicyToItem(context,item,Constants.REMOVE,epa);
  }
}
Program: 51876
Project: 51876
Buggy source:
protected void removeUserItemPolicies(Context context,Item item,EPerson e) throws SQLException, AuthorizeException {
  if (e != null) {
    authorizeService.removeEPersonPolicies(context,item,e);
    List<Bundle> bundles=item.getBundles();
    for (    Bundle bundle : bundles) {
      authorizeService.removeEPersonPolicies(context,bundle,e);
      List<Bitstream> bitstreams=bundle.getBitstreams();
      for (      Bitstream bitstream : bitstreams) {
        authorizeService.removeEPersonPolicies(context,bitstream,e);
      }
    }
    if (e.getID().equals(item.getSubmitter().getID())) {
      grantSubmitterReadPolicies(context,item);
    }
  }
}

Fixed version (ground truth):
public void removeUserItemPolicies(Context context,Item item,EPerson e) throws SQLException, AuthorizeException {
  if (e != null) {
    authorizeService.removeEPersonPolicies(context,item,e);
    List<Bundle> bundles=item.getBundles();
    for (    Bundle bundle : bundles) {
      authorizeService.removeEPersonPolicies(context,bundle,e);
      List<Bitstream> bitstreams=bundle.getBitstreams();
      for (      Bitstream bitstream : bitstreams) {
        authorizeService.removeEPersonPolicies(context,bitstream,e);
      }
    }
    if (e.getID().equals(item.getSubmitter().getID())) {
      grantSubmitterReadPolicies(context,item);
    }
  }
}
Program: 51877
Project: 51877
Buggy source:
@Override public void update(Context context,MetadataValue metadataValue,boolean updateLastModified) throws SQLException, AuthorizeException {
  if (updateLastModified) {
    authorizeService.authorizeAction(context,metadataValue.getDSpaceObject(),Constants.WRITE);
    contentServiceFactory.getDSpaceObjectService(metadataValue.getDSpaceObject()).updateLastModified(context,metadataValue.getDSpaceObject());
  }
  update(context,metadataValue);
}

Fixed version (ground truth):
@Override public void update(Context context,MetadataValue metadataValue,boolean updateLastModified) throws SQLException, AuthorizeException {
  if (updateLastModified) {
    authorizeService.authorizeAction(context,metadataValue.getDSpaceObject(),Constants.WRITE);
    DSpaceObjectService<DSpaceObject> dSpaceObjectService=contentServiceFactory.getDSpaceObjectService(metadataValue.getDSpaceObject());
    DSpaceObject dso=dSpaceObjectService.find(context,metadataValue.getDSpaceObject().getID());
    dSpaceObjectService.updateLastModified(context,dso);
  }
  update(context,metadataValue);
}
Program: 51879
Project: 51879
Buggy source:
@Override public Item installItem(Context c,InProgressSubmission is,String suppliedHandle) throws SQLException, AuthorizeException {
  Item item=is.getItem();
  try {
    if (suppliedHandle == null) {
      identifierService.register(c,item);
    }
 else {
      identifierService.register(c,item,suppliedHandle);
    }
  }
 catch (  IdentifierException e) {
    throw new RuntimeException("String_Node_Str",e);
  }
  populateMetadata(c,item);
  item=finishItem(c,item,is);
  itemService.inheritCollectionDefaultPolicies(c,item,is.getCollection());
  return item;
}

Fixed version (ground truth):
@Override public Item installItem(Context c,InProgressSubmission is,String suppliedHandle) throws SQLException, AuthorizeException {
  Item item=is.getItem();
  Collection collection=is.getCollection();
  try {
    if (suppliedHandle == null) {
      identifierService.register(c,item);
    }
 else {
      identifierService.register(c,item,suppliedHandle);
    }
  }
 catch (  IdentifierException e) {
    throw new RuntimeException("String_Node_Str",e);
  }
  populateMetadata(c,item);
  item=finishItem(c,item,is);
  itemService.inheritCollectionDefaultPolicies(c,item,collection);
  return item;
}
Program: 51881
Project: 51881
Buggy source:
@Override public List<ResourcePolicy> findByTypeIdGroupAction(Context context,DSpaceObject dso,Group group,int action,int notPolicyID) throws SQLException {
  Criteria criteria=createCriteria(context,ResourcePolicy.class);
  criteria.add(Restrictions.and(Restrictions.eq("String_Node_Str",dso),Restrictions.eq("String_Node_Str",group),Restrictions.eq("String_Node_Str",action)));
  criteria.setMaxResults(1);
  List<ResourcePolicy> results;
  if (notPolicyID != -1) {
    criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq("String_Node_Str",action))));
  }
  return list(criteria);
}

Fixed version (ground truth):
@Override public List<ResourcePolicy> findByTypeIdGroupAction(Context context,DSpaceObject dso,Group group,int action,int notPolicyID) throws SQLException {
  Criteria criteria=createCriteria(context,ResourcePolicy.class);
  criteria.add(Restrictions.and(Restrictions.eq("String_Node_Str",dso),Restrictions.eq("String_Node_Str",group),Restrictions.eq("String_Node_Str",action)));
  criteria.setMaxResults(1);
  List<ResourcePolicy> results;
  if (notPolicyID != -1) {
    criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq("String_Node_Str",notPolicyID))));
  }
  return list(criteria);
}
Program: 51882
Project: 51882
Buggy source:
@Override public void removeMetadataValues(Context context,T dso,List<MetadataValue> values) throws SQLException {
  Iterator<MetadataValue> metadata=dso.getMetadata().iterator();
  while (metadata.hasNext()) {
    MetadataValue metadataValue=metadata.next();
    if (values.contains(metadataValue)) {
      metadata.remove();
    }
  }
  dso.setMetadataModified();
}

Fixed version (ground truth):
@Override public void removeMetadataValues(Context context,T dso,List<MetadataValue> values) throws SQLException {
  Iterator<MetadataValue> metadata=dso.getMetadata().iterator();
  while (metadata.hasNext()) {
    MetadataValue metadataValue=metadata.next();
    if (values.contains(metadataValue)) {
      metadata.remove();
      metadataValueService.delete(context,metadataValue);
    }
  }
  dso.setMetadataModified();
}
Program: 51883
Project: 51883
Buggy source:
@Override public void clearMetadata(Context context,T dso,String schema,String element,String qualifier,String lang) throws SQLException {
  Iterator<MetadataValue> metadata=dso.getMetadata().iterator();
  while (metadata.hasNext()) {
    MetadataValue metadataValue=metadata.next();
    if (match(schema,element,qualifier,lang,metadataValue)) {
      metadataValue.setDSpaceObject(null);
      metadata.remove();
    }
  }
  dso.setMetadataModified();
}

Fixed version (ground truth):
@Override public void clearMetadata(Context context,T dso,String schema,String element,String qualifier,String lang) throws SQLException {
  Iterator<MetadataValue> metadata=dso.getMetadata().iterator();
  while (metadata.hasNext()) {
    MetadataValue metadataValue=metadata.next();
    if (match(schema,element,qualifier,lang,metadataValue)) {
      metadata.remove();
      metadataValueService.delete(context,metadataValue);
    }
  }
  dso.setMetadataModified();
}
Program: 51884
Project: 51884
Buggy source:
/** 
 * Commit the current transaction with the database, persisting any pending changes. The database connection is not closed and can be reused afterwards. <b>WARNING: After calling this method all previously fetched entities are "detached" (pending changes are not tracked anymore). You have to reload all entities you still want to work manually after this method call (see   {@link Context#reloadEntity(ReloadableEntity)}).</b>
 * @throws SQLException When committing the transaction in the database fails.
 */
public void commit() throws SQLException {
  if (!isValid()) {
    log.info("String_Node_Str");
  }
  try {
    if (isValid() && !isReadOnly()) {
      dispatchEvents();
    }
  }
  finally {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + getCacheSize());
    }
    if (dbConnection != null) {
      dbConnection.commit();
      reloadContextBoundEntities();
    }
  }
}

Fixed version (ground truth):
/** 
 * Commit the current transaction with the database, persisting any pending changes. The database connection is not closed and can be reused afterwards. <b>WARNING: After calling this method all previously fetched entities are "detached" (pending changes are not tracked anymore). You have to reload all entities you still want to work with manually after this method call (see   {@link Context#reloadEntity(ReloadableEntity)}).</b>
 * @throws SQLException When committing the transaction in the database fails.
 */
public void commit() throws SQLException {
  if (!isValid()) {
    log.info("String_Node_Str");
  }
  try {
    if (isValid() && !isReadOnly()) {
      dispatchEvents();
    }
  }
  finally {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + getCacheSize());
    }
    if (dbConnection != null) {
      dbConnection.commit();
      reloadContextBoundEntities();
    }
  }
}
Program: 51885
Project: 51885
Buggy source:
/** 
 * Clear the cache of all object that have been read from the database so far. This will also free up (heap space) memory. You should use this method when processing a large number of records. <b>WARNING: After calling this method all previously fetched entities are "detached" (pending changes are not tracked anymore). You have to reload all entities you still want to work manually after this method call (see   {@link Context#reloadEntity(ReloadableEntity)}).</b> This method will take care of reloading the current user.
 * @throws SQLException When clearing the entity cache fails
 */
public void clearCache() throws SQLException {
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + getCacheSize());
  }
  this.getDBConnection().clearCache();
  reloadContextBoundEntities();
}

Fixed version (ground truth):
/** 
 * Clear the cache of all object that have been read from the database so far. This will also free up (heap space) memory. You should use this method when processing a large number of records. <b>WARNING: After calling this method all previously fetched entities are "detached" (pending changes are not tracked anymore). You have to reload all entities you still want to work with manually after this method call (see   {@link Context#reloadEntity(ReloadableEntity)}).</b> This method will take care of reloading the current user.
 * @throws SQLException When clearing the entity cache fails
 */
public void clearCache() throws SQLException {
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + getCacheSize());
  }
  this.getDBConnection().clearCache();
  reloadContextBoundEntities();
}
Program: 51886
Project: 51886
Buggy source:
@Override public void ingest(Context context,DSpaceObject dso,Element root,boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException {
  if (dso.getType() != Constants.ITEM) {
    throw new CrosswalkObjectNotSupported("String_Node_Str");
  }
  Item item=(Item)dso;
  if (root == null) {
    System.err.println("String_Node_Str");
    return;
  }
  List<Element> metadata=root.getChildren("String_Node_Str",DIM_NS);
  for (  Element field : metadata) {
    String schema=field.getAttributeValue("String_Node_Str");
    String element=field.getAttributeValue("String_Node_Str");
    String qualifier=field.getAttributeValue("String_Node_Str");
    CrosswalkUtils.checkMetadata(context,schema,element,qualifier,createMissingMetadataFields);
    itemService.addMetadata(context,item,schema,element,qualifier,field.getAttributeValue("String_Node_Str"),field.getText());
  }
}

Fixed version (ground truth):
@Override public void ingest(Context context,DSpaceObject dso,Element root,boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException {
  if (dso.getType() != Constants.ITEM) {
    throw new CrosswalkObjectNotSupported("String_Node_Str");
  }
  Item item=(Item)dso;
  if (root == null) {
    System.err.println("String_Node_Str");
    return;
  }
  List<Element> metadata=root.getChildren("String_Node_Str",DIM_NS);
  for (  Element field : metadata) {
    String schema=field.getAttributeValue("String_Node_Str");
    String element=field.getAttributeValue("String_Node_Str");
    String qualifier=field.getAttributeValue("String_Node_Str");
    MetadataField metadataField=metadataValidator.checkMetadata(context,schema,element,qualifier,createMissingMetadataFields);
    itemService.addMetadata(context,item,metadataField,field.getAttributeValue("String_Node_Str"),field.getText());
  }
}
Program: 51887
Project: 51887
Buggy source:
@Override public void ingest(Context context,DSpaceObject dso,Element root,boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException {
  if (dso.getType() != Constants.ITEM) {
    throw new CrosswalkObjectNotSupported("String_Node_Str");
  }
  Item item=(Item)dso;
  if (root == null) {
    System.err.println("String_Node_Str");
    return;
  }
  List<Element> metadata=root.getChildren();
  for (  Element element : metadata) {
    String lang=element.getAttributeValue("String_Node_Str",Namespace.XML_NAMESPACE);
    if (lang == null) {
      lang=element.getAttributeValue("String_Node_Str");
    }
    CrosswalkUtils.checkMetadata(context,MetadataSchema.DC_SCHEMA,element.getName(),null,createMissingMetadataFields);
    itemService.addMetadata(context,item,"String_Node_Str",element.getName(),null,lang,element.getText());
  }
}

Fixed version (ground truth):
@Override public void ingest(Context context,DSpaceObject dso,Element root,boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException {
  if (dso.getType() != Constants.ITEM) {
    throw new CrosswalkObjectNotSupported("String_Node_Str");
  }
  Item item=(Item)dso;
  if (root == null) {
    System.err.println("String_Node_Str");
    return;
  }
  List<Element> metadata=root.getChildren();
  for (  Element element : metadata) {
    String lang=element.getAttributeValue("String_Node_Str",Namespace.XML_NAMESPACE);
    if (lang == null) {
      lang=element.getAttributeValue("String_Node_Str");
    }
    MetadataField metadataField=metadataValidator.checkMetadata(context,MetadataSchema.DC_SCHEMA,element.getName(),null,createMissingMetadataFields);
    itemService.addMetadata(context,item,metadataField,lang,element.getText());
  }
}
Program: 51888
Project: 51888
Buggy source:
public void filiate(Context c,Community parent,Community child) throws SQLException, AuthorizeException, IOException {
  Community childDad=CollectionUtils.isNotEmpty(child.getParentCommunities()) ? child.getParentCommunities().iterator().next() : null;
  if (childDad != null) {
    System.out.println("String_Node_Str" + child.getID() + "String_Node_Str"+ childDad.getID());
    System.exit(1);
  }
  List<Community> parentDads=parent.getParentCommunities();
  for (int i=0; i < parentDads.size(); i++) {
    if (parentDads.get(i).getID().equals(child.getID())) {
      System.out.println("String_Node_Str");
      System.exit(1);
    }
  }
  communityService.addSubcommunity(c,parent,child);
  c.complete();
  System.out.println("String_Node_Str" + parent.getID() + "String_Node_Str"+ child.getID()+ "String_Node_Str");
}

Fixed version (ground truth):
/** 
 * @param c context
 * @param parent parent Community
 * @param child child community
 * @throws SQLException if database error
 * @throws AuthorizeException if authorize error
 * @throws IOException if IO error
 */
public void filiate(Context c,Community parent,Community child) throws SQLException, AuthorizeException, IOException {
  Community childDad=CollectionUtils.isNotEmpty(child.getParentCommunities()) ? child.getParentCommunities().iterator().next() : null;
  if (childDad != null) {
    System.out.println("String_Node_Str" + child.getID() + "String_Node_Str"+ childDad.getID());
    System.exit(1);
  }
  List<Community> parentDads=parent.getParentCommunities();
  for (int i=0; i < parentDads.size(); i++) {
    if (parentDads.get(i).getID().equals(child.getID())) {
      System.out.println("String_Node_Str");
      System.exit(1);
    }
  }
  communityService.addSubcommunity(c,parent,child);
  c.complete();
  System.out.println("String_Node_Str" + parent.getID() + "String_Node_Str"+ child.getID()+ "String_Node_Str");
}
Program: 51889
Project: 51889
Buggy source:
protected Community resolveCommunity(Context c,String communityID) throws SQLException {
  Community community=null;
  if (communityID.indexOf('/') != -1) {
    community=(Community)handleService.resolveToObject(c,communityID);
    if ((community == null) || (community.getType() != Constants.COMMUNITY)) {
      community=null;
    }
  }
 else {
    community=communityService.find(c,UUID.fromString(communityID));
  }
  return community;
}

Fixed version (ground truth):
/** 
 * Find a community by ID
 * @param c context
 * @param communityID community ID
 * @return Community object
 * @throws SQLException if database error
 */
protected Community resolveCommunity(Context c,String communityID) throws SQLException {
  Community community=null;
  if (communityID.indexOf('/') != -1) {
    community=(Community)handleService.resolveToObject(c,communityID);
    if ((community == null) || (community.getType() != Constants.COMMUNITY)) {
      community=null;
    }
  }
 else {
    community=communityService.find(c,UUID.fromString(communityID));
  }
  return community;
}
Program: 51891
Project: 51891
Buggy source:
public void defiliate(Context c,Community parent,Community child) throws SQLException, AuthorizeException, IOException {
  List<Community> parentKids=parent.getSubcommunities();
  boolean isChild=false;
  for (int i=0; i < parentKids.size(); i++) {
    if (parentKids.get(i).getID().equals(child.getID())) {
      isChild=true;
      break;
    }
  }
  if (!isChild) {
    System.out.println("String_Node_Str");
    System.exit(1);
  }
  child.getParentCommunities().remove(parent);
  parent.getSubcommunities().remove(child);
  communityService.update(c,child);
  communityService.update(c,parent);
  c.complete();
  System.out.println("String_Node_Str" + child.getID() + "String_Node_Str"+ parent.getID()+ "String_Node_Str");
}

Fixed version (ground truth):
/** 
 * @param c context
 * @param parent parent Community
 * @param child child community
 * @throws SQLException if database error
 * @throws AuthorizeException if authorize error
 * @throws IOException if IO error
 */
public void defiliate(Context c,Community parent,Community child) throws SQLException, AuthorizeException, IOException {
  List<Community> parentKids=parent.getSubcommunities();
  boolean isChild=false;
  for (int i=0; i < parentKids.size(); i++) {
    if (parentKids.get(i).getID().equals(child.getID())) {
      isChild=true;
      break;
    }
  }
  if (!isChild) {
    System.out.println("String_Node_Str");
    System.exit(1);
  }
  child.getParentCommunities().remove(parent);
  parent.getSubcommunities().remove(child);
  communityService.update(c,child);
  communityService.update(c,parent);
  c.complete();
  System.out.println("String_Node_Str" + child.getID() + "String_Node_Str"+ parent.getID()+ "String_Node_Str");
}
Program: 51892
Project: 51892
Buggy source:
/** 
 * constructor, which just creates and object with a ready context
 * @throws Exception
 */
protected CreateAdministrator() throws Exception {
  context=new Context();
  groupService=EPersonServiceFactory.getInstance().getGroupService();
  ePersonService=EPersonServiceFactory.getInstance().getEPersonService();
}

Fixed version (ground truth):
/** 
 * constructor, which just creates and object with a ready context
 * @throws Exception if error
 */
protected CreateAdministrator() throws Exception {
  context=new Context();
  groupService=EPersonServiceFactory.getInstance().getGroupService();
  ePersonService=EPersonServiceFactory.getInstance().getEPersonService();
}
Program: 51894
Project: 51894
Buggy source:
/** 
 * For invoking via the command line.  If called with no command line arguments, it will negotiate with the user for the administrator details
 * @param argv command-line arguments
 */
public static void main(String[] argv) throws Exception {
  CommandLineParser parser=new PosixParser();
  Options options=new Options();
  CreateAdministrator ca=new CreateAdministrator();
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  CommandLine line=parser.parse(options,argv);
  if (line.hasOption("String_Node_Str") && line.hasOption("String_Node_Str") && line.hasOption("String_Node_Str")&& line.hasOption("String_Node_Str")&& line.hasOption("String_Node_Str")) {
    ca.createAdministrator(line.getOptionValue("String_Node_Str"),line.getOptionValue("String_Node_Str"),line.getOptionValue("String_Node_Str"),line.getOptionValue("String_Node_Str"),line.getOptionValue("String_Node_Str"));
  }
 else {
    ca.negotiateAdministratorDetails();
  }
}

Fixed version (ground truth):
/** 
 * For invoking via the command line.  If called with no command line arguments, it will negotiate with the user for the administrator details
 * @param argv command-line arguments
 * @throws Exception if error
 */
public static void main(String[] argv) throws Exception {
  CommandLineParser parser=new PosixParser();
  Options options=new Options();
  CreateAdministrator ca=new CreateAdministrator();
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  CommandLine line=parser.parse(options,argv);
  if (line.hasOption("String_Node_Str") && line.hasOption("String_Node_Str") && line.hasOption("String_Node_Str")&& line.hasOption("String_Node_Str")&& line.hasOption("String_Node_Str")) {
    ca.createAdministrator(line.getOptionValue("String_Node_Str"),line.getOptionValue("String_Node_Str"),line.getOptionValue("String_Node_Str"),line.getOptionValue("String_Node_Str"),line.getOptionValue("String_Node_Str"));
  }
 else {
    ca.negotiateAdministratorDetails();
  }
}
Program: 51895
Project: 51895
Buggy source:
/** 
 * Create the administrator with the given details.  If the user already exists then they are simply upped to administrator status
 * @param email	the email for the user
 * @param first	user's first name
 * @param last	user's last name
 * @param language preferred language
 * @param pw	desired password
 * @throws Exception
 */
protected void createAdministrator(String email,String first,String last,String language,String pw) throws Exception {
  context.setIgnoreAuthorization(true);
  Group admins=groupService.findByName(context,Group.ADMIN);
  if (admins == null) {
    throw new IllegalStateException("String_Node_Str");
  }
  EPerson eperson=ePersonService.findByEmail(context,email);
  if (eperson == null) {
    eperson=ePersonService.create(context);
    eperson.setEmail(email);
    eperson.setCanLogIn(true);
    eperson.setRequireCertificate(false);
    eperson.setSelfRegistered(false);
  }
  eperson.setLastName(context,last);
  eperson.setFirstName(context,first);
  eperson.setLanguage(context,language);
  ePersonService.setPassword(eperson,pw);
  ePersonService.update(context,eperson);
  groupService.addMember(context,admins,eperson);
  groupService.update(context,admins);
  context.complete();
  System.out.println("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Create the administrator with the given details.  If the user already exists then they are simply upped to administrator status
 * @param email	the email for the user
 * @param first	user's first name
 * @param last	user's last name
 * @param language preferred language
 * @param pw	desired password
 * @throws Exception if error
 */
protected void createAdministrator(String email,String first,String last,String language,String pw) throws Exception {
  context.setIgnoreAuthorization(true);
  Group admins=groupService.findByName(context,Group.ADMIN);
  if (admins == null) {
    throw new IllegalStateException("String_Node_Str");
  }
  EPerson eperson=ePersonService.findByEmail(context,email);
  if (eperson == null) {
    eperson=ePersonService.create(context);
    eperson.setEmail(email);
    eperson.setCanLogIn(true);
    eperson.setRequireCertificate(false);
    eperson.setSelfRegistered(false);
  }
  eperson.setLastName(context,last);
  eperson.setFirstName(context,first);
  eperson.setLanguage(context,language);
  ePersonService.setPassword(eperson,pw);
  ePersonService.update(context,eperson);
  groupService.addMember(context,admins,eperson);
  groupService.update(context,admins);
  context.complete();
  System.out.println("String_Node_Str");
}
Program: 51897
Project: 51897
Buggy source:
private static String getSchemaName(Context context,MetadataField mdField) throws SQLException, RegistryExportException {
  String name=schemaMap.get(mdField.getMetadataSchema().getSchemaID());
  if (name == null) {
    MetadataSchema mdSchema=metadataSchemaService.find(context,mdField.getMetadataSchema().getSchemaID());
    if (mdSchema != null) {
      name=mdSchema.getName();
      schemaMap.put(mdSchema.getSchemaID(),name);
    }
 else {
      throw new RegistryExportException("String_Node_Str");
    }
  }
  return name;
}

Fixed version (ground truth):
/** 
 * Helper method to retrieve a schema name for the field. Caches the name after looking up the id.
 * @param context DSpace Context
 * @param mdField DSpace metadata field
 * @return name of schema
 * @throws SQLException if database error
 * @throws RegistryExportException if export error
 */
private static String getSchemaName(Context context,MetadataField mdField) throws SQLException, RegistryExportException {
  String name=schemaMap.get(mdField.getMetadataSchema().getSchemaID());
  if (name == null) {
    MetadataSchema mdSchema=metadataSchemaService.find(context,mdField.getMetadataSchema().getSchemaID());
    if (mdSchema != null) {
      name=mdSchema.getName();
      schemaMap.put(mdSchema.getSchemaID(),name);
    }
 else {
      throw new RegistryExportException("String_Node_Str");
    }
  }
  return name;
}
Program: 51898
Project: 51898
Buggy source:
/** 
 * @param args
 * @throws ParseException 
 * @throws SAXException 
 * @throws IOException 
 * @throws SQLException 
 * @throws RegistryExportException 
 */
public static void main(String[] args) throws ParseException, SQLException, IOException, SAXException, RegistryExportException {
  CommandLineParser parser=new PosixParser();
  Options options=new Options();
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  CommandLine line=parser.parse(options,args);
  String file=null;
  String schema=null;
  if (line.hasOption('f')) {
    file=line.getOptionValue('f');
  }
 else {
    usage();
    System.exit(0);
  }
  if (line.hasOption('s')) {
    schema=line.getOptionValue('s');
  }
  saveRegistry(file,schema);
}

Fixed version (ground truth):
/** 
 * @param args commandline arguments
 * @throws ParseException if parser error 
 * @throws SAXException if XML parse error
 * @throws IOException if IO error
 * @throws SQLException if database error
 * @throws RegistryExportException if export error
 */
public static void main(String[] args) throws ParseException, SQLException, IOException, SAXException, RegistryExportException {
  CommandLineParser parser=new PosixParser();
  Options options=new Options();
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  CommandLine line=parser.parse(options,args);
  String file=null;
  String schema=null;
  if (line.hasOption('f')) {
    file=line.getOptionValue('f');
  }
 else {
    usage();
    System.exit(0);
  }
  if (line.hasOption('s')) {
    schema=line.getOptionValue('s');
  }
  saveRegistry(file,schema);
}
Program: 51899
Project: 51899
Buggy source:
/** 
 * Serialize a single schema (namespace) registry entry
 * @param xmlSerializer
 * @param mdSchema
 * @throws SAXException
 * @throws RegistryExportException
 */
private static void saveSchema(XMLSerializer xmlSerializer,MetadataSchema mdSchema) throws SAXException, RegistryExportException {
  if (mdSchema == null) {
    throw new RegistryExportException("String_Node_Str");
  }
  String name=mdSchema.getName();
  String namespace=mdSchema.getNamespace();
  if (name == null || "String_Node_Str".equals(name)) {
    System.out.println("String_Node_Str");
    return;
  }
  if (namespace == null || "String_Node_Str".equals(namespace)) {
    System.out.println("String_Node_Str");
    return;
  }
  xmlSerializer.startElement("String_Node_Str",null);
  xmlSerializer.startElement("String_Node_Str",null);
  xmlSerializer.characters(name.toCharArray(),0,name.length());
  xmlSerializer.endElement("String_Node_Str");
  xmlSerializer.startElement("String_Node_Str",null);
  xmlSerializer.characters(namespace.toCharArray(),0,namespace.length());
  xmlSerializer.endElement("String_Node_Str");
  xmlSerializer.endElement("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Serialize a single schema (namespace) registry entry
 * @param xmlSerializer XML serializer
 * @param mdSchema DSpace metadata schema
 * @throws SAXException if XML error
 * @throws RegistryExportException if export error
 */
private static void saveSchema(XMLSerializer xmlSerializer,MetadataSchema mdSchema) throws SAXException, RegistryExportException {
  if (mdSchema == null) {
    throw new RegistryExportException("String_Node_Str");
  }
  String name=mdSchema.getName();
  String namespace=mdSchema.getNamespace();
  if (name == null || "String_Node_Str".equals(name)) {
    System.out.println("String_Node_Str");
    return;
  }
  if (namespace == null || "String_Node_Str".equals(namespace)) {
    System.out.println("String_Node_Str");
    return;
  }
  xmlSerializer.startElement("String_Node_Str",null);
  xmlSerializer.startElement("String_Node_Str",null);
  xmlSerializer.characters(name.toCharArray(),0,name.length());
  xmlSerializer.endElement("String_Node_Str");
  xmlSerializer.startElement("String_Node_Str",null);
  xmlSerializer.characters(namespace.toCharArray(),0,namespace.length());
  xmlSerializer.endElement("String_Node_Str");
  xmlSerializer.endElement("String_Node_Str");
}
Program: 51900
Project: 51900
Buggy source:
public static void saveRegistry(String file,String schema) throws SQLException, IOException, SAXException, RegistryExportException {
  Context context=new Context();
  context.setIgnoreAuthorization(true);
  OutputFormat xmlFormat=new OutputFormat(Method.XML,"String_Node_Str",true);
  xmlFormat.setLineWidth(120);
  xmlFormat.setIndent(4);
  XMLSerializer xmlSerializer=new XMLSerializer(new BufferedWriter(new FileWriter(file)),xmlFormat);
  xmlSerializer.startDocument();
  xmlSerializer.startElement("String_Node_Str",null);
  saveSchema(context,xmlSerializer,schema);
  List<MetadataField> mdFields=null;
  if (schema != null && !"String_Node_Str".equals(schema)) {
    MetadataSchema mdSchema=metadataSchemaService.find(context,schema);
    if (mdSchema == null) {
      throw new RegistryExportException("String_Node_Str");
    }
    mdFields=metadataFieldService.findAllInSchema(context,mdSchema);
  }
 else {
    mdFields=metadataFieldService.findAll(context);
  }
  for (  MetadataField mdField : mdFields) {
    saveType(context,xmlSerializer,mdField);
  }
  xmlSerializer.endElement("String_Node_Str");
  xmlSerializer.endDocument();
  context.abort();
}

Fixed version (ground truth):
/** 
 * Save a registry to a filepath
 * @param file filepath
 * @param schema schema definition to save
 * @throws SQLException if database error
 * @throws IOException if IO error
 * @throws SAXException if XML error
 * @throws RegistryExportException if export error
 */
public static void saveRegistry(String file,String schema) throws SQLException, IOException, SAXException, RegistryExportException {
  Context context=new Context();
  context.setIgnoreAuthorization(true);
  OutputFormat xmlFormat=new OutputFormat(Method.XML,"String_Node_Str",true);
  xmlFormat.setLineWidth(120);
  xmlFormat.setIndent(4);
  XMLSerializer xmlSerializer=new XMLSerializer(new BufferedWriter(new FileWriter(file)),xmlFormat);
  xmlSerializer.startDocument();
  xmlSerializer.startElement("String_Node_Str",null);
  saveSchema(context,xmlSerializer,schema);
  List<MetadataField> mdFields=null;
  if (schema != null && !"String_Node_Str".equals(schema)) {
    MetadataSchema mdSchema=metadataSchemaService.find(context,schema);
    if (mdSchema == null) {
      throw new RegistryExportException("String_Node_Str");
    }
    mdFields=metadataFieldService.findAllInSchema(context,mdSchema);
  }
 else {
    mdFields=metadataFieldService.findAll(context);
  }
  for (  MetadataField mdField : mdFields) {
    saveType(context,xmlSerializer,mdField);
  }
  xmlSerializer.endElement("String_Node_Str");
  xmlSerializer.endDocument();
  context.abort();
}
Program: 51902
Project: 51902
Buggy source:
/** 
 * Load the data from the specified file path into the database
 * @param file	the file path containing the source data
 */
public static void loadRegistry(String file,boolean forceUpdate) throws SQLException, IOException, TransformerException, ParserConfigurationException, AuthorizeException, SAXException, NonUniqueMetadataException, RegistryImportException {
  Context context=null;
  try {
    context=new Context();
    context.turnOffAuthorisationSystem();
    Document document=RegistryImporter.loadXML(file);
    NodeList schemaNodes=XPathAPI.selectNodeList(document,"String_Node_Str");
    for (int i=0; i < schemaNodes.getLength(); i++) {
      Node n=schemaNodes.item(i);
      loadSchema(context,n,forceUpdate);
    }
    NodeList typeNodes=XPathAPI.selectNodeList(document,"String_Node_Str");
    for (int i=0; i < typeNodes.getLength(); i++) {
      Node n=typeNodes.item(i);
      loadType(context,n);
    }
    context.restoreAuthSystemState();
    context.complete();
  }
  finally {
    if (context != null && context.isValid())     context.abort();
  }
}

Fixed version (ground truth):
/** 
 * Load the data from the specified file path into the database
 * @param file	the file path containing the source data
 * @param forceUpdate whether to force update
 * @throws SQLException if database error
 * @throws IOException if IO error
 * @throws TransformerException if transformer error
 * @throws ParserConfigurationException if config error
 * @throws AuthorizeException if authorization error
 * @throws SAXException if parser error
 * @throws NonUniqueMetadataException if duplicate metadata
 * @throws RegistryImportException if import fails
 */
public static void loadRegistry(String file,boolean forceUpdate) throws SQLException, IOException, TransformerException, ParserConfigurationException, AuthorizeException, SAXException, NonUniqueMetadataException, RegistryImportException {
  Context context=null;
  try {
    context=new Context();
    context.turnOffAuthorisationSystem();
    Document document=RegistryImporter.loadXML(file);
    NodeList schemaNodes=XPathAPI.selectNodeList(document,"String_Node_Str");
    for (int i=0; i < schemaNodes.getLength(); i++) {
      Node n=schemaNodes.item(i);
      loadSchema(context,n,forceUpdate);
    }
    NodeList typeNodes=XPathAPI.selectNodeList(document,"String_Node_Str");
    for (int i=0; i < typeNodes.getLength(); i++) {
      Node n=typeNodes.item(i);
      loadType(context,n);
    }
    context.restoreAuthSystemState();
    context.complete();
  }
  finally {
    if (context != null && context.isValid())     context.abort();
  }
}
Program: 51904
Project: 51904
Buggy source:
/** 
 * main method for reading user input from the command line
 */
public static void main(String[] args) throws ParseException, SQLException, IOException, TransformerException, ParserConfigurationException, AuthorizeException, SAXException, NonUniqueMetadataException, RegistryImportException {
  boolean forceUpdate=false;
  CommandLineParser parser=new PosixParser();
  Options options=new Options();
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",false,"String_Node_Str");
  CommandLine line=parser.parse(options,args);
  String file=null;
  if (line.hasOption('f')) {
    file=line.getOptionValue('f');
  }
 else {
    usage();
    System.exit(0);
  }
  forceUpdate=line.hasOption('u');
  loadRegistry(file,forceUpdate);
}

Fixed version (ground truth):
/** 
 * main method for reading user input from the command line
 * @param args arguments
 * @throws ParseException if parse error
 * @throws SQLException if database error
 * @throws IOException if IO error
 * @throws TransformerException if transformer error
 * @throws ParserConfigurationException if config error
 * @throws AuthorizeException if authorization error
 * @throws SAXException if parser error
 * @throws NonUniqueMetadataException if duplicate metadata
 * @throws RegistryImportException if import fails
 */
public static void main(String[] args) throws ParseException, SQLException, IOException, TransformerException, ParserConfigurationException, AuthorizeException, SAXException, NonUniqueMetadataException, RegistryImportException {
  boolean forceUpdate=false;
  CommandLineParser parser=new PosixParser();
  Options options=new Options();
  options.addOption("String_Node_Str","String_Node_Str",true,"String_Node_Str");
  options.addOption("String_Node_Str","String_Node_Str",false,"String_Node_Str");
  CommandLine line=parser.parse(options,args);
  String file=null;
  if (line.hasOption('f')) {
    file=line.getOptionValue('f');
  }
 else {
    usage();
    System.exit(0);
  }
  forceUpdate=line.hasOption('u');
  loadRegistry(file,forceUpdate);
}
Program: 51905
Project: 51905
Buggy source:
/** 
 * create an exception with an inner exception
 * @param e
 */
public RegistryExportException(Throwable e){
  super(e);
}

Fixed version (ground truth):
/** 
 * create an exception with an inner exception
 * @param e reference to Throwable
 */
public RegistryExportException(Throwable e){
  super(e);
}
Program: 51906
Project: 51906
Buggy source:
/** 
 * Allows adding singleton services and providers in at runtime or  after the service manager has started up. This is the same as   {@link #registerService(String,Object)}except that it allows the core service manager to startup your  service for you instead of you providing a service to the core. In general, it is better if you use your own service manager  (like Spring or Guice) to manage your services  and simply  inherit the core service beans from the DSpace core service manager using the special capabilities of  {@link #getServiceByName(String,Class)}.
 * @see ServiceManager#getServiceByName(String,Class)
 * @param name the name of the service (must be unique)
 * @param type the class type of the service (must be in the current classloader)
 * @throws IllegalArgumentException if the service cannot be registered because the name is taken or type is invalid or other
 */
public <T>T registerServiceClass(String name,Class<T> type);

Fixed version (ground truth):
/** 
 * Allows adding singleton services and providers in at runtime or  after the service manager has started up. This is the same as   {@link #registerService(String,Object)}except that it allows the core service manager to startup your  service for you instead of you providing a service to the core. In general, it is better if you use your own service manager  (like Spring or Guice) to manage your services  and simply  inherit the core service beans from the DSpace core service manager using the special capabilities of  {@link #getServiceByName(String,Class)}.
 * @see ServiceManager#getServiceByName(String,Class)
 * @param < T > Class type
 * @param name the name of the service (must be unique)
 * @param type the class type of the service (must be in the current classloader)
 * @return the service class
 * @throws IllegalArgumentException if the service cannot be registered because the name is taken or type is invalid or other
 */
public <T>T registerServiceClass(String name,Class<T> type);
Program: 51907
Project: 51907
Buggy source:
/** 
 * Allows a service to be unregistered (which will only work if nothing depends on it). This is primarily used for providers, filters, plugins, etc.  which were registered but are no longer available because the  context they are running in is shutting down or restarting. <br/> WARNING: This should not be used to attempt to unregister core  services as that will fail.
 * @param name the name of the service (must be unique)
 * @throws IllegalArgumentException if the bean cannot be unregistered
 */
public void unregisterService(String name);

Fixed version (ground truth):
/** 
 * Allows a service to be unregistered (which will only work if nothing depends on it). This is primarily used for providers, filters, plugins, etc.  which were registered but are no longer available because the  context they are running in is shutting down or restarting. <br> <em>WARNING: This should not be used to attempt to unregister core  services as that will fail.</em>
 * @param name the name of the service (must be unique)
 * @throws IllegalArgumentException if the bean cannot be unregistered
 */
public void unregisterService(String name);