Program: 3270
Project: 3270
Buggy source:
/** 
 * Common code to ingest roles from a Document.
 * @param context DSpace Context
 * @param parent the Parent DSpaceObject
 * @param document the XML Document
 * @throws SQLException
 * @throws AuthorizeException
 * @throws PackageException
 */
static void ingestDocument(Context context,DSpaceObject parent,PackageParameters params,Document document) throws SQLException, AuthorizeException, PackageException {
  String myEmail=context.getCurrentUser().getEmail();
  String myNetid=context.getCurrentUser().getNetid();
  NodeList users=document.getElementsByTagName(RoleDisseminator.EPERSON);
  for (int i=0; i < users.getLength(); i++) {
    Element user=(Element)users.item(i);
    NodeList emails=user.getElementsByTagName(RoleDisseminator.EMAIL);
    NodeList netids=user.getElementsByTagName(RoleDisseminator.NETID);
    EPerson eperson;
    EPerson collider;
    String email=null;
    String netid=null;
    String identity;
    if (emails.getLength() > 0) {
      email=emails.item(0).getTextContent();
      if (email.equals(myEmail))       continue;
      identity=email;
      collider=EPerson.findByEmail(context,identity);
    }
 else     if (netids.getLength() > 0) {
      netid=netids.item(0).getTextContent();
      if (netid.equals(myNetid))       continue;
      identity=netid;
      collider=EPerson.findByNetid(context,identity);
    }
 else     throw new PackageException("String_Node_Str");
    if (null != collider)     if (params.replaceModeEnabled()) {
      eperson=collider;
    }
 else     if (params.keepExistingModeEnabled()) {
      log.warn("String_Node_Str",identity);
      continue;
    }
 else     throw new PackageException("String_Node_Str" + identity + "String_Node_Str");
 else {
      eperson=EPerson.create(context);
      log.info("String_Node_Str",identity);
    }
    eperson.setEmail(email);
    eperson.setNetid(netid);
    NodeList data;
    data=user.getElementsByTagName(RoleDisseminator.FIRST_NAME);
    if (data.getLength() > 0)     eperson.setFirstName(data.item(0).getTextContent());
 else     eperson.setFirstName(null);
    data=user.getElementsByTagName(RoleDisseminator.LAST_NAME);
    if (data.getLength() > 0)     eperson.setLastName(data.item(0).getTextContent());
 else     eperson.setLastName(null);
    data=user.getElementsByTagName(RoleDisseminator.LANGUAGE);
    if (data.getLength() > 0)     eperson.setLanguage(data.item(0).getTextContent());
 else     eperson.setLanguage(null);
    data=user.getElementsByTagName(RoleDisseminator.CAN_LOGIN);
    eperson.setCanLogIn(data.getLength() > 0);
    data=user.getElementsByTagName(RoleDisseminator.REQUIRE_CERTIFICATE);
    eperson.setRequireCertificate(data.getLength() > 0);
    data=user.getElementsByTagName(RoleDisseminator.SELF_REGISTERED);
    eperson.setSelfRegistered(data.getLength() > 0);
    data=user.getElementsByTagName(RoleDisseminator.PASSWORD_HASH);
    if (data.getLength() > 0)     eperson.setPasswordHash(data.item(0).getTextContent());
 else     eperson.setPasswordHash(null);
    eperson.update();
  }
  NodeList groups=document.getElementsByTagName(RoleDisseminator.GROUP);
  for (int groupx=0; groupx < groups.getLength(); groupx++) {
    Element group=(Element)groups.item(groupx);
    String name=group.getAttribute(RoleDisseminator.NAME);
    name=PackageUtils.crosswalkDefaultGroupName(context,name);
    Group groupObj=null;
    Group collider=Group.findByName(context,name);
    if (null != collider) {
      if (params.replaceModeEnabled()) {
        for (        Group member : collider.getMemberGroups())         collider.removeMember(member);
        for (        EPerson member : collider.getMembers())         collider.removeMember(member);
        log.info("String_Node_Str",name);
        groupObj=collider;
      }
 else       if (params.keepExistingModeEnabled()) {
        log.warn("String_Node_Str",name);
        continue;
      }
 else       throw new PackageException("String_Node_Str" + name + "String_Node_Str");
    }
 else {
      String type=group.getAttribute(RoleDisseminator.TYPE);
      if (type != null && !type.isEmpty() && parent != null) {
        if (parent.getType() == Constants.COLLECTION) {
          Collection collection=(Collection)parent;
          if (type.equals(RoleDisseminator.GROUP_TYPE_ADMIN))           groupObj=collection.createAdministrators();
 else           if (type.equals(RoleDisseminator.GROUP_TYPE_SUBMIT))           groupObj=collection.createSubmitters();
 else           if (type.equals(RoleDisseminator.GROUP_TYPE_WORKFLOW_STEP_1))           groupObj=collection.createWorkflowGroup(1);
 else           if (type.equals(RoleDisseminator.GROUP_TYPE_WORKFLOW_STEP_2))           groupObj=collection.createWorkflowGroup(2);
 else           if (type.equals(RoleDisseminator.GROUP_TYPE_WORKFLOW_STEP_3))           groupObj=collection.createWorkflowGroup(3);
        }
 else         if (parent.getType() == Constants.COMMUNITY) {
          Community community=(Community)parent;
          if (type.equals(RoleDisseminator.GROUP_TYPE_ADMIN))           groupObj=community.createAdministrators();
        }
      }
      if (groupObj == null) {
        groupObj=Group.create(context);
        groupObj.setName(name);
      }
      log.info("String_Node_Str",groupObj.getName());
    }
    NodeList members=group.getElementsByTagName(RoleDisseminator.MEMBER);
    for (int memberx=0; memberx < members.getLength(); memberx++) {
      Element member=(Element)members.item(memberx);
      String memberName=member.getAttribute(RoleDisseminator.NAME);
      EPerson memberEPerson=EPerson.findByEmail(context,memberName);
      groupObj.addMember(memberEPerson);
    }
    groupObj.update();
  }
  for (int groupx=0; groupx < groups.getLength(); groupx++) {
    Element group=(Element)groups.item(groupx);
    String name=group.getAttribute(RoleDisseminator.NAME);
    name=PackageUtils.crosswalkDefaultGroupName(context,name);
    Group groupObj=Group.findByName(context,name);
    NodeList members=group.getElementsByTagName(RoleDisseminator.MEMBER_GROUP);
    for (int memberx=0; memberx < members.getLength(); memberx++) {
      Element member=(Element)members.item(memberx);
      String memberName=member.getAttribute(RoleDisseminator.NAME);
      memberName=PackageUtils.crosswalkDefaultGroupName(context,memberName);
      Group memberGroup=Group.findByName(context,memberName);
      groupObj.addMember(memberGroup);
    }
    groupObj.update();
  }
}

Fixed version (ground truth):
/** 
 * Common code to ingest roles from a Document.
 * @param context DSpace Context
 * @param parent the Parent DSpaceObject
 * @param document the XML Document
 * @throws SQLException
 * @throws AuthorizeException
 * @throws PackageException
 */
static void ingestDocument(Context context,DSpaceObject parent,PackageParameters params,Document document) throws SQLException, AuthorizeException, PackageException {
  String myEmail=context.getCurrentUser().getEmail();
  String myNetid=context.getCurrentUser().getNetid();
  NodeList users=document.getElementsByTagName(RoleDisseminator.EPERSON);
  for (int i=0; i < users.getLength(); i++) {
    Element user=(Element)users.item(i);
    NodeList emails=user.getElementsByTagName(RoleDisseminator.EMAIL);
    NodeList netids=user.getElementsByTagName(RoleDisseminator.NETID);
    EPerson eperson;
    EPerson collider;
    String email=null;
    String netid=null;
    String identity;
    if (emails.getLength() > 0) {
      email=emails.item(0).getTextContent();
      if (email.equals(myEmail))       continue;
      identity=email;
      collider=EPerson.findByEmail(context,identity);
    }
 else     if (netids.getLength() > 0) {
      netid=netids.item(0).getTextContent();
      if (netid.equals(myNetid))       continue;
      identity=netid;
      collider=EPerson.findByNetid(context,identity);
    }
 else     throw new PackageException("String_Node_Str");
    if (null != collider)     if (params.replaceModeEnabled()) {
      eperson=collider;
    }
 else     if (params.keepExistingModeEnabled()) {
      log.warn("String_Node_Str",identity);
      continue;
    }
 else     throw new PackageException("String_Node_Str" + identity + "String_Node_Str");
 else {
      eperson=EPerson.create(context);
      log.info("String_Node_Str",identity);
    }
    eperson.setEmail(email);
    eperson.setNetid(netid);
    NodeList data;
    data=user.getElementsByTagName(RoleDisseminator.FIRST_NAME);
    if (data.getLength() > 0)     eperson.setFirstName(data.item(0).getTextContent());
 else     eperson.setFirstName(null);
    data=user.getElementsByTagName(RoleDisseminator.LAST_NAME);
    if (data.getLength() > 0)     eperson.setLastName(data.item(0).getTextContent());
 else     eperson.setLastName(null);
    data=user.getElementsByTagName(RoleDisseminator.LANGUAGE);
    if (data.getLength() > 0)     eperson.setLanguage(data.item(0).getTextContent());
 else     eperson.setLanguage(null);
    data=user.getElementsByTagName(RoleDisseminator.CAN_LOGIN);
    eperson.setCanLogIn(data.getLength() > 0);
    data=user.getElementsByTagName(RoleDisseminator.REQUIRE_CERTIFICATE);
    eperson.setRequireCertificate(data.getLength() > 0);
    data=user.getElementsByTagName(RoleDisseminator.SELF_REGISTERED);
    eperson.setSelfRegistered(data.getLength() > 0);
    data=user.getElementsByTagName(RoleDisseminator.PASSWORD_HASH);
    if (data.getLength() > 0)     eperson.setPasswordHash(data.item(0).getTextContent());
 else     eperson.setPasswordHash(null);
    eperson.update();
  }
  NodeList groups=document.getElementsByTagName(RoleDisseminator.GROUP);
  for (int groupx=0; groupx < groups.getLength(); groupx++) {
    Element group=(Element)groups.item(groupx);
    String name=group.getAttribute(RoleDisseminator.NAME);
    try {
      name=PackageUtils.translateGroupNameForImport(context,name);
    }
 catch (    PackageException pe) {
      log.warn("String_Node_Str" + name + "String_Node_Str"+ "String_Node_Str");
      continue;
    }
    Group groupObj=null;
    Group collider=Group.findByName(context,name);
    if (null != collider) {
      if (params.replaceModeEnabled()) {
        for (        Group member : collider.getMemberGroups())         collider.removeMember(member);
        for (        EPerson member : collider.getMembers()) {
          if (!(collider.equals(Group.find(context,1)) && member.equals(context.getCurrentUser())))           collider.removeMember(member);
        }
        log.info("String_Node_Str",name);
        groupObj=collider;
      }
 else       if (params.keepExistingModeEnabled()) {
        log.warn("String_Node_Str",name);
        continue;
      }
 else       throw new PackageException("String_Node_Str" + name + "String_Node_Str");
    }
 else {
      String type=group.getAttribute(RoleDisseminator.TYPE);
      if (type != null && !type.isEmpty() && parent != null) {
        if (parent.getType() == Constants.COLLECTION) {
          Collection collection=(Collection)parent;
          if (type.equals(RoleDisseminator.GROUP_TYPE_ADMIN))           groupObj=collection.createAdministrators();
 else           if (type.equals(RoleDisseminator.GROUP_TYPE_SUBMIT))           groupObj=collection.createSubmitters();
 else           if (type.equals(RoleDisseminator.GROUP_TYPE_WORKFLOW_STEP_1))           groupObj=collection.createWorkflowGroup(1);
 else           if (type.equals(RoleDisseminator.GROUP_TYPE_WORKFLOW_STEP_2))           groupObj=collection.createWorkflowGroup(2);
 else           if (type.equals(RoleDisseminator.GROUP_TYPE_WORKFLOW_STEP_3))           groupObj=collection.createWorkflowGroup(3);
        }
 else         if (parent.getType() == Constants.COMMUNITY) {
          Community community=(Community)parent;
          if (type.equals(RoleDisseminator.GROUP_TYPE_ADMIN))           groupObj=community.createAdministrators();
        }
      }
      if (groupObj == null) {
        groupObj=Group.create(context);
        groupObj.setName(name);
      }
      log.info("String_Node_Str",groupObj.getName());
    }
    NodeList members=group.getElementsByTagName(RoleDisseminator.MEMBER);
    for (int memberx=0; memberx < members.getLength(); memberx++) {
      Element member=(Element)members.item(memberx);
      String memberName=member.getAttribute(RoleDisseminator.NAME);
      EPerson memberEPerson=EPerson.findByEmail(context,memberName);
      groupObj.addMember(memberEPerson);
    }
    groupObj.update();
  }
  for (int groupx=0; groupx < groups.getLength(); groupx++) {
    Element group=(Element)groups.item(groupx);
    String name=group.getAttribute(RoleDisseminator.NAME);
    try {
      name=PackageUtils.translateGroupNameForImport(context,name);
    }
 catch (    PackageException pe) {
      continue;
    }
    Group groupObj=Group.findByName(context,name);
    NodeList members=group.getElementsByTagName(RoleDisseminator.MEMBER_GROUP);
    for (int memberx=0; memberx < members.getLength(); memberx++) {
      Element member=(Element)members.item(memberx);
      String memberName=member.getAttribute(RoleDisseminator.NAME);
      memberName=PackageUtils.translateGroupNameForImport(context,memberName);
      Group memberGroup=Group.findByName(context,memberName);
      groupObj.addMember(memberGroup);
    }
    groupObj.update();
  }
}