Program: 52020
Project: 52020
Buggy source:
/** 
 * Run an import. The import can either be read-only to detect changes, or can write changes as it goes.
 * @param change Whether or not to write the changes to the database
 * @param useWorkflow Whether the workflows should be used when creating new items
 * @param workflowNotify If the workflows should be used, whether to send notifications or not
 * @param useTemplate Use collection template if create new item
 * @return An array of BulkEditChange elements representing the items that have changed
 * @throws MetadataImportException if something goes wrong
 */
public List<BulkEditChange> runImport(boolean change,boolean useWorkflow,boolean workflowNotify,boolean useTemplate) throws MetadataImportException {
  ArrayList<BulkEditChange> changes=new ArrayList<BulkEditChange>();
  try {
    for (    DSpaceCSVLine line : toImport) {
      int id=line.getID();
      if (csv.hasActions() && (!"String_Node_Str".equals(line.getAction())) && (id == -1)) {
        throw new MetadataImportException("String_Node_Str");
      }
      if (id != -1) {
        Item item=Item.find(c,id);
        if (item == null) {
          throw new MetadataImportException("String_Node_Str" + id);
        }
        BulkEditChange whatHasChanged=new BulkEditChange(item);
        List<String> collections=line.get("String_Node_Str");
        if (collections != null) {
          if (collections.size() == 0) {
            throw new MetadataImportException("String_Node_Str" + item.getHandle());
          }
          Collection[] actualCollections=item.getCollections();
          compare(item,collections,actualCollections,whatHasChanged,change);
        }
        for (        String md : line.keys()) {
          if (!"String_Node_Str".equals(md)) {
            String[] fromCSV=line.get(md).toArray(new String[line.get(md).size()]);
            if (!isAuthorityControlledField(md)) {
              for (int i=0; i < fromCSV.length; i++) {
                int pos=fromCSV[i].indexOf(DSpaceCSV.authoritySeparator);
                if (pos > -1) {
                  fromCSV[i]=fromCSV[i].substring(0,pos);
                }
              }
            }
            compare(item,fromCSV,change,md,whatHasChanged);
          }
        }
        if (csv.hasActions()) {
          String action=line.getAction();
          if ("String_Node_Str".equals(action)) {
          }
 else           if ("String_Node_Str".equals(action)) {
            if (!ConfigurationManager.getBooleanProperty("String_Node_Str","String_Node_Str",false)) {
              throw new MetadataImportException("String_Node_Str");
            }
            Collection[] owners=item.getCollections();
            for (            Collection owner : owners) {
              if (change) {
                owner.removeItem(item);
              }
            }
            whatHasChanged.setDeleted();
          }
 else           if ("String_Node_Str".equals(action)) {
            if (!item.isWithdrawn()) {
              if (change) {
                item.withdraw();
              }
              whatHasChanged.setWithdrawn();
            }
          }
 else           if ("String_Node_Str".equals(action)) {
            if (item.isWithdrawn()) {
              if (change) {
                item.reinstate();
              }
              whatHasChanged.setReinstated();
            }
          }
 else {
            throw new MetadataImportException("String_Node_Str" + action);
          }
        }
        if (whatHasChanged.hasChanges()) {
          changes.add(whatHasChanged);
        }
      }
 else {
        if (c.getCurrentUser() == null) {
          throw new MetadataImportException("String_Node_Str");
        }
        BulkEditChange whatHasChanged=new BulkEditChange();
        for (        String md : line.keys()) {
          if (!"String_Node_Str".equals(md)) {
            String[] fromCSV=line.get(md).toArray(new String[line.get(md).size()]);
            if (!isAuthorityControlledField(md)) {
              for (int i=0; i < fromCSV.length; i++) {
                int pos=fromCSV[i].indexOf(DSpaceCSV.authoritySeparator);
                if (pos > -1) {
                  fromCSV[i]=fromCSV[i].substring(0,pos);
                }
              }
            }
            add(fromCSV,md,whatHasChanged);
          }
        }
        List<String> collections=line.get("String_Node_Str");
        if (collections == null) {
          throw new MetadataImportException("String_Node_Str");
        }
        ArrayList<Collection> check=new ArrayList<Collection>();
        Collection collection;
        for (        String handle : collections) {
          try {
            collection=(Collection)HandleManager.resolveToObject(c,handle);
            if (collection == null) {
              throw new MetadataImportException("String_Node_Str" + handle + "String_Node_Str");
            }
            if (check.contains(collection)) {
              throw new MetadataImportException("String_Node_Str" + handle);
            }
 else {
              check.add(collection);
            }
          }
 catch (          Exception ex) {
            throw new MetadataImportException("String_Node_Str" + handle + "String_Node_Str",ex);
          }
        }
        boolean first=true;
        for (        String handle : collections) {
          Collection extra=(Collection)HandleManager.resolveToObject(c,handle);
          if (first) {
            whatHasChanged.setOwningCollection(extra);
          }
 else {
            whatHasChanged.registerNewMappedCollection(extra);
          }
          first=false;
        }
        if (change) {
          String collectionHandle=line.get("String_Node_Str").get(0);
          collection=(Collection)HandleManager.resolveToObject(c,collectionHandle);
          WorkspaceItem wsItem=WorkspaceItem.create(c,collection,useTemplate);
          Item item=wsItem.getItem();
          for (          Metadatum dcv : whatHasChanged.getAdds()) {
            item.addMetadata(dcv.schema,dcv.element,dcv.qualifier,dcv.language,dcv.value,dcv.authority,dcv.confidence);
          }
          if (useWorkflow) {
            if (ConfigurationManager.getProperty("String_Node_Str","String_Node_Str").equals("String_Node_Str")) {
              if (workflowNotify) {
                XmlWorkflowManager.start(c,wsItem);
              }
 else {
                XmlWorkflowManager.startWithoutNotify(c,wsItem);
              }
            }
 else {
              if (workflowNotify) {
                WorkflowManager.start(c,wsItem);
              }
 else {
                WorkflowManager.startWithoutNotify(c,wsItem);
              }
            }
          }
 else {
            InstallItem.installItem(c,wsItem);
          }
          if (line.get("String_Node_Str").size() > 0) {
            for (int i=1; i < collections.size(); i++) {
              String handle=collections.get(i);
              Collection extra=(Collection)HandleManager.resolveToObject(c,handle);
              extra.addItem(item);
            }
          }
          c.commit();
          whatHasChanged.setItem(item);
        }
        changes.add(whatHasChanged);
      }
    }
  }
 catch (  MetadataImportException mie) {
    throw mie;
  }
catch (  Exception e) {
    e.printStackTrace();
  }
  return changes;
}

Fixed version (ground truth):
/** 
 * Run an import. The import can either be read-only to detect changes, or can write changes as it goes.
 * @param change Whether or not to write the changes to the database
 * @param useWorkflow Whether the workflows should be used when creating new items
 * @param workflowNotify If the workflows should be used, whether to send notifications or not
 * @param useTemplate Use collection template if create new item
 * @return An array of BulkEditChange elements representing the items that have changed
 * @throws MetadataImportException if something goes wrong
 */
public List<BulkEditChange> runImport(boolean change,boolean useWorkflow,boolean workflowNotify,boolean useTemplate) throws MetadataImportException {
  ArrayList<BulkEditChange> changes=new ArrayList<BulkEditChange>();
  try {
    for (    DSpaceCSVLine line : toImport) {
      int id=line.getID();
      if (csv.hasActions() && (!"String_Node_Str".equals(line.getAction())) && (id == -1)) {
        throw new MetadataImportException("String_Node_Str");
      }
      if (id != -1) {
        Item item=Item.find(c,id);
        if (item == null) {
          throw new MetadataImportException("String_Node_Str" + id);
        }
        BulkEditChange whatHasChanged=new BulkEditChange(item);
        List<String> collections=line.get("String_Node_Str");
        if (collections != null) {
          if (collections.size() == 0) {
            throw new MetadataImportException("String_Node_Str" + item.getHandle());
          }
          Collection[] actualCollections=item.getCollections();
          compare(item,collections,actualCollections,whatHasChanged,change);
        }
        for (        String md : line.keys()) {
          if (!"String_Node_Str".equals(md)) {
            String[] fromCSV=line.get(md).toArray(new String[line.get(md).size()]);
            if (!isAuthorityControlledField(md)) {
              for (int i=0; i < fromCSV.length; i++) {
                int pos=fromCSV[i].indexOf(DSpaceCSV.authoritySeparator);
                if (pos > -1) {
                  fromCSV[i]=fromCSV[i].substring(0,pos);
                }
              }
            }
            compare(item,fromCSV,change,md,whatHasChanged,line);
          }
        }
        if (csv.hasActions()) {
          String action=line.getAction();
          if ("String_Node_Str".equals(action)) {
          }
 else           if ("String_Node_Str".equals(action)) {
            if (!ConfigurationManager.getBooleanProperty("String_Node_Str","String_Node_Str",false)) {
              throw new MetadataImportException("String_Node_Str");
            }
            Collection[] owners=item.getCollections();
            for (            Collection owner : owners) {
              if (change) {
                owner.removeItem(item);
              }
            }
            whatHasChanged.setDeleted();
          }
 else           if ("String_Node_Str".equals(action)) {
            if (!item.isWithdrawn()) {
              if (change) {
                item.withdraw();
              }
              whatHasChanged.setWithdrawn();
            }
          }
 else           if ("String_Node_Str".equals(action)) {
            if (item.isWithdrawn()) {
              if (change) {
                item.reinstate();
              }
              whatHasChanged.setReinstated();
            }
          }
 else {
            throw new MetadataImportException("String_Node_Str" + action);
          }
        }
        if (whatHasChanged.hasChanges()) {
          changes.add(whatHasChanged);
        }
      }
 else {
        if (c.getCurrentUser() == null) {
          throw new MetadataImportException("String_Node_Str");
        }
        BulkEditChange whatHasChanged=new BulkEditChange();
        for (        String md : line.keys()) {
          if (!"String_Node_Str".equals(md)) {
            String[] fromCSV=line.get(md).toArray(new String[line.get(md).size()]);
            if (!isAuthorityControlledField(md)) {
              for (int i=0; i < fromCSV.length; i++) {
                int pos=fromCSV[i].indexOf(DSpaceCSV.authoritySeparator);
                if (pos > -1) {
                  fromCSV[i]=fromCSV[i].substring(0,pos);
                }
              }
            }
            add(fromCSV,md,whatHasChanged);
          }
        }
        List<String> collections=line.get("String_Node_Str");
        if (collections == null) {
          throw new MetadataImportException("String_Node_Str");
        }
        ArrayList<Collection> check=new ArrayList<Collection>();
        Collection collection;
        for (        String handle : collections) {
          try {
            collection=(Collection)HandleManager.resolveToObject(c,handle);
            if (collection == null) {
              throw new MetadataImportException("String_Node_Str" + handle + "String_Node_Str");
            }
            if (check.contains(collection)) {
              throw new MetadataImportException("String_Node_Str" + handle);
            }
 else {
              check.add(collection);
            }
          }
 catch (          Exception ex) {
            throw new MetadataImportException("String_Node_Str" + handle + "String_Node_Str",ex);
          }
        }
        boolean first=true;
        for (        String handle : collections) {
          Collection extra=(Collection)HandleManager.resolveToObject(c,handle);
          if (first) {
            whatHasChanged.setOwningCollection(extra);
          }
 else {
            whatHasChanged.registerNewMappedCollection(extra);
          }
          first=false;
        }
        if (change) {
          String collectionHandle=line.get("String_Node_Str").get(0);
          collection=(Collection)HandleManager.resolveToObject(c,collectionHandle);
          WorkspaceItem wsItem=WorkspaceItem.create(c,collection,useTemplate);
          Item item=wsItem.getItem();
          for (          Metadatum dcv : whatHasChanged.getAdds()) {
            item.addMetadata(dcv.schema,dcv.element,dcv.qualifier,dcv.language,dcv.value,dcv.authority,dcv.confidence);
          }
          if (useWorkflow) {
            if (ConfigurationManager.getProperty("String_Node_Str","String_Node_Str").equals("String_Node_Str")) {
              if (workflowNotify) {
                XmlWorkflowManager.start(c,wsItem);
              }
 else {
                XmlWorkflowManager.startWithoutNotify(c,wsItem);
              }
            }
 else {
              if (workflowNotify) {
                WorkflowManager.start(c,wsItem);
              }
 else {
                WorkflowManager.startWithoutNotify(c,wsItem);
              }
            }
          }
 else {
            InstallItem.installItem(c,wsItem);
          }
          if (line.get("String_Node_Str").size() > 0) {
            for (int i=1; i < collections.size(); i++) {
              String handle=collections.get(i);
              Collection extra=(Collection)HandleManager.resolveToObject(c,handle);
              extra.addItem(item);
            }
          }
          c.commit();
          whatHasChanged.setItem(item);
        }
        changes.add(whatHasChanged);
      }
    }
  }
 catch (  MetadataImportException mie) {
    throw mie;
  }
catch (  Exception e) {
    e.printStackTrace();
  }
  return changes;
}