Program: 120788
Project: 120788
Buggy source:
/** 
 * upsert, one record, one time.
 */
public UpsertResult[] upsert(String tablename,String upsertkey,OMElement[] updatefields,String[] fieldsToNull) throws Exception {
  SObject item=new SObject();
  item.setType(tablename);
  item.setExtraElement(updatefields);
  item.setFieldsToNull(fieldsToNull);
  upsertItems.add(item);
  upsertKeyColumn=upsertkey;
  if (upsertItems.size() >= commitLevel) {
    SObject[] upds=upsertItems.toArray(new SObject[upsertItems.size()]);
    Upsert upsert=new Upsert();
    upsert.setSObjects(upds);
    upsert.setExternalIDFieldName(upsertKeyColumn);
    UpsertResult[] upsertResults=stub.upsert(upsert,sh,co,null,null,null,null,null,null,null,null,null).getResult();
    upsertItems.clear();
    upds=null;
    if (exceptionForErrors && upsertResults != null && upsertResults.length != 0) {
      for (      UpsertResult result : upsertResults) {
        StringBuilder errors=new StringBuilder("String_Node_Str");
        if (result.getSuccess()) {
        }
 else {
          errors=addLog(result.getErrors());
        }
        if (exceptionForErrors && errors.toString().length() > 0) {
          if (logWriter != null) {
            logWriter.close();
          }
          throw new Exception(errors.toString());
        }
      }
    }
    return upsertResults;
  }
  return null;
}

Fixed version (ground truth):
/** 
 * upsert, one record, one time.
 */
public UpsertResult[] upsert(String tablename,String upsertkey,OMElement[] updatefields,String[] fieldsToNull) throws Exception {
  SObject item=new SObject();
  item.setType(tablename);
  item.setExtraElement(updatefields);
  item.setFieldsToNull(fieldsToNull);
  upsertItems.add(item);
  upsertKeyColumn=upsertkey;
  if (upsertItems.size() >= commitLevel) {
    SObject[] upds=upsertItems.toArray(new SObject[upsertItems.size()]);
    changedItemKeys=new String[upds.length];
    for (int ix=0; ix < upds.length; ++ix) {
      changedItemKeys[ix]="String_Node_Str" + upsertKeyColumn + "String_Node_Str";
      OMElement[] oms=upds[ix].getExtraElement();
      for (int iy=0; iy < oms.length; ++iy) {
        if (upsertKeyColumn != null && oms[iy] != null && upsertKeyColumn.equals(oms[iy].getLocalName())) {
          changedItemKeys[ix]=oms[iy].getText();
          break;
        }
      }
    }
    Upsert upsert=new Upsert();
    upsert.setSObjects(upds);
    upsert.setExternalIDFieldName(upsertKeyColumn);
    UpsertResult[] upsertResults=stub.upsert(upsert,sh,co,null,null,null,null,null,null,null,null,null).getResult();
    upsertItems.clear();
    upds=null;
    if (upsertResults != null && upsertResults.length != 0) {
      int batch_idx=-1;
      for (      UpsertResult result : upsertResults) {
        ++batch_idx;
        StringBuilder errors=new StringBuilder("String_Node_Str");
        if (result.getSuccess()) {
        }
 else {
          errors=addLog(result.getErrors(),batch_idx < changedItemKeys.length ? changedItemKeys[batch_idx] : "String_Node_Str");
        }
        if (exceptionForErrors && errors.toString().length() > 0) {
          if (logWriter != null) {
            logWriter.close();
          }
          throw new Exception(errors.toString());
        }
      }
    }
    return upsertResults;
  }
  return null;
}