Program: 52225
Project: 52225
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 ArrayList<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 (id != -1) {
        Item item=Item.find(c,id);
        BulkEditChange whatHasChanged=new BulkEditChange(item);
        ArrayList<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);
        }
        Enumeration<String> e=line.keys();
        while (e.hasMoreElements()) {
          String md=e.nextElement();
          if (!"String_Node_Str".equals(md)) {
            String[] fromCSV=line.get(md).toArray(new String[line.get(md).size()]);
            compare(item,fromCSV,change,md,whatHasChanged);
          }
        }
        if (whatHasChanged.hasChanges()) {
          changes.add(whatHasChanged);
        }
      }
 else {
        if (c.getCurrentUser() == null) {
          throw new MetadataImportException("String_Node_Str");
        }
        Enumeration<String> e=line.keys();
        BulkEditChange whatHasChanged=new BulkEditChange();
        while (e.hasMoreElements()) {
          String md=e.nextElement();
          if (!"String_Node_Str".equals(md)) {
            String[] fromCSV=line.get(md).toArray(new String[line.get(md).size()]);
            add(fromCSV,md,whatHasChanged);
          }
        }
        if (line.get("String_Node_Str") == null) {
          throw new MetadataImportException("String_Node_Str");
        }
        ArrayList<String> collections=line.get("String_Node_Str");
        ArrayList<Collection> check=new ArrayList<Collection>();
        for (int i=0; i < collections.size(); i++) {
          String handle=collections.get(i);
          Collection collection;
          try {
            collection=(Collection)HandleManager.resolveToObject(c,handle);
            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");
          }
        }
        for (int i=0; i < collections.size(); i++) {
          String handle=collections.get(i);
          Collection extra=(Collection)HandleManager.resolveToObject(c,handle);
          whatHasChanged.registerNewOwningCollection(extra);
        }
        if (change) {
          String collectionHandle=line.get("String_Node_Str").get(0);
          Collection collection=(Collection)HandleManager.resolveToObject(c,collectionHandle);
          WorkspaceItem wsItem=WorkspaceItem.create(c,collection,useTemplate);
          Item item=wsItem.getItem();
          for (          DCValue dcv : whatHasChanged.getAdds()) {
            item.addMetadata(dcv.schema,dcv.element,dcv.qualifier,dcv.language,dcv.value);
          }
          if ((useWorkflow) && (workflowNotify)) {
            WorkflowManager.start(c,wsItem);
          }
 else           if (useWorkflow) {
            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 ArrayList<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 (id != -1) {
        Item item=Item.find(c,id);
        BulkEditChange whatHasChanged=new BulkEditChange(item);
        ArrayList<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);
        }
        Enumeration<String> e=line.keys();
        while (e.hasMoreElements()) {
          String md=e.nextElement();
          if (!"String_Node_Str".equals(md)) {
            String[] fromCSV=line.get(md).toArray(new String[line.get(md).size()]);
            compare(item,fromCSV,change,md,whatHasChanged);
          }
        }
        if (whatHasChanged.hasChanges()) {
          changes.add(whatHasChanged);
        }
      }
 else {
        if (c.getCurrentUser() == null) {
          throw new MetadataImportException("String_Node_Str");
        }
        Enumeration<String> e=line.keys();
        BulkEditChange whatHasChanged=new BulkEditChange();
        while (e.hasMoreElements()) {
          String md=e.nextElement();
          if (!"String_Node_Str".equals(md)) {
            String[] fromCSV=line.get(md).toArray(new String[line.get(md).size()]);
            add(fromCSV,md,whatHasChanged);
          }
        }
        ArrayList<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");
          }
        }
        for (        String handle : collections) {
          Collection extra=(Collection)HandleManager.resolveToObject(c,handle);
          whatHasChanged.registerNewOwningCollection(extra);
        }
        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 (          DCValue dcv : whatHasChanged.getAdds()) {
            item.addMetadata(dcv.schema,dcv.element,dcv.qualifier,dcv.language,dcv.value);
          }
          if ((useWorkflow) && (workflowNotify)) {
            WorkflowManager.start(c,wsItem);
          }
 else           if (useWorkflow) {
            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;
}