nus-yam/ex-repair huggingface dataset:
Program: 3914
Project: 3914
Buggy source:
/** 
 * Builds the HttpWebRequest object for current service request with exception handling.
 * @return An HttpWebRequest instance
 * @throws Exception on error
 */
protected HttpWebRequest buildEwsHttpWebRequest() throws Exception {
  try {
    HttpWebRequest request=service.prepareHttpWebRequest();
    service.traceHttpRequestHeaders(TraceFlags.EwsRequestHttpHeaders,request);
    ByteArrayOutputStream requestStream=(ByteArrayOutputStream)request.getOutputStream();
    EwsServiceXmlWriter writer=new EwsServiceXmlWriter(service,requestStream);
    boolean needSignature=service.getCredentials() != null && service.getCredentials().isNeedSignature();
    writer.setRequireWSSecurityUtilityNamespace(needSignature);
    writeToXml(writer);
    if (needSignature) {
      service.getCredentials().sign(requestStream);
    }
    service.traceXml(TraceFlags.EwsRequest,requestStream);
    return request;
  }
 catch (  IOException e) {
    throw new ServiceRequestException(String.format("String_Node_Str",e.getMessage()),e);
  }
}

Fixed version (ground truth):
private HttpWebRequest buildEwsHttpWebRequest(HttpWebRequest request) throws Exception {
  try {
    service.traceHttpRequestHeaders(TraceFlags.EwsRequestHttpHeaders,request);
    ByteArrayOutputStream requestStream=(ByteArrayOutputStream)request.getOutputStream();
    EwsServiceXmlWriter writer=new EwsServiceXmlWriter(service,requestStream);
    boolean needSignature=service.getCredentials() != null && service.getCredentials().isNeedSignature();
    writer.setRequireWSSecurityUtilityNamespace(needSignature);
    writeToXml(writer);
    if (needSignature) {
      service.getCredentials().sign(requestStream);
    }
    service.traceXml(TraceFlags.EwsRequest,requestStream);
    return request;
  }
 catch (  IOException e) {
    throw new ServiceRequestException(String.format("String_Node_Str",e.getMessage()),e);
  }
}
Program: 3915
Project: 3915
Buggy source:
/** 
 * Validates this instance.
 * @throws Exception the exception
 */
public void validate() throws Exception {
  if (this.owner.isNew() && this.owner.getService().getRequestedServerVersion().ordinal() >= ExchangeVersion.Exchange2010_SP2.ordinal()) {
    boolean contactPhotoFound=false;
    for (int attachmentIndex=0; attachmentIndex < this.getAddedItems().size(); attachmentIndex++) {
      final Attachment attachment=this.getAddedItems().get(attachmentIndex);
      if (attachment != null && attachment.isNew() && attachment instanceof FileAttachment) {
        if (((FileAttachment)attachment).isContactPhoto()) {
          if (contactPhotoFound) {
            throw new ServiceValidationException("String_Node_Str");
          }
          contactPhotoFound=true;
        }
      }
      attachment.validate(attachmentIndex);
    }
  }
}

Fixed version (ground truth):
/** 
 * Validates this instance.
 * @throws Exception the exception
 */
public void validate() throws Exception {
  if (this.owner.isNew() && this.owner.getService().getRequestedServerVersion().ordinal() >= ExchangeVersion.Exchange2010_SP2.ordinal()) {
    boolean contactPhotoFound=false;
    for (int attachmentIndex=0; attachmentIndex < this.getAddedItems().size(); attachmentIndex++) {
      final Attachment attachment=this.getAddedItems().get(attachmentIndex);
      if (attachment != null) {
        if (attachment.isNew() && attachment instanceof FileAttachment) {
          if (((FileAttachment)attachment).isContactPhoto()) {
            if (contactPhotoFound) {
              throw new ServiceValidationException("String_Node_Str");
            }
            contactPhotoFound=true;
          }
        }
        attachment.validate(attachmentIndex);
      }
    }
  }
}
Program: 3916
Project: 3916
Buggy source:
/** 
 * Compares the transitions.
 * @param x The first transition.
 * @param y The second transition.
 * @return A negative number if x is less than y, 0 if x and y are equal, apositive number if x is greater than y.
 */
@Override public int compare(TimeZoneTransition x,TimeZoneTransition y){
  if (x == y) {
    return 0;
  }
 else   if (x instanceof TimeZoneTransition) {
    return -1;
  }
 else   if (y instanceof TimeZoneTransition) {
    return 1;
  }
 else {
    AbsoluteDateTransition firstTransition=(AbsoluteDateTransition)x;
    AbsoluteDateTransition secondTransition=(AbsoluteDateTransition)y;
    return firstTransition.getDateTime().compareTo(secondTransition.getDateTime());
  }
}

Fixed version (ground truth):
/** 
 * Compares the transitions.
 * @param x The first transition.
 * @param y The second transition.
 * @return A negative number if x is less than y, 0 if x and y are equal, apositive number if x is greater than y.
 */
@Override public int compare(final TimeZoneTransition x,final TimeZoneTransition y){
  if (x == y) {
    return 0;
  }
 else   if (x != null && y != null) {
    final AbsoluteDateTransition firstTransition=(AbsoluteDateTransition)x;
    final AbsoluteDateTransition secondTransition=(AbsoluteDateTransition)y;
    final Date firstDateTime=firstTransition.getDateTime();
    final Date secondDateTime=secondTransition.getDateTime();
    return firstDateTime.compareTo(secondDateTime);
  }
 else   if (y == null) {
    return 1;
  }
  return -1;
}
Program: 3917
Project: 3917
Buggy source:
/** 
 * Internals the load from XML.
 * @param reader      The reader.
 * @param propertyBag The property bag.
 * @throws Exception the exception
 */
protected void internalLoadFromXml(EwsServiceXmlReader reader,PropertyBag propertyBag) throws Exception {
  OutParam<Object> complexProperty=new OutParam<Object>();
  boolean justCreated=getPropertyInstance(propertyBag,complexProperty);
  if (!justCreated && this.hasFlag(PropertyDefinitionFlags.UpdateCollectionItems,propertyBag.getOwner().getService().getRequestedServerVersion())) {
    ComplexProperty c=(ComplexProperty)complexProperty.getParam();
    if (complexProperty.getParam() instanceof ComplexProperty) {
      c.updateFromXml(reader,reader.getLocalName());
    }
  }
 else {
    ComplexProperty c=(ComplexProperty)complexProperty.getParam();
    c.loadFromXml(reader,reader.getLocalName());
  }
  propertyBag.setObjectFromPropertyDefinition(this,complexProperty.getParam());
}

Fixed version (ground truth):
/** 
 * Internals the load from XML.
 * @param reader      The reader.
 * @param propertyBag The property bag.
 * @throws Exception the exception
 */
protected void internalLoadFromXml(EwsServiceXmlReader reader,PropertyBag propertyBag) throws Exception {
  OutParam<Object> complexProperty=new OutParam<Object>();
  boolean justCreated=getPropertyInstance(propertyBag,complexProperty);
  if (!justCreated && this.hasFlag(PropertyDefinitionFlags.UpdateCollectionItems,propertyBag.getOwner().getService().getRequestedServerVersion())) {
    Object c=complexProperty.getParam();
    if (c instanceof ComplexProperty) {
      ((ComplexProperty)c).updateFromXml(reader,reader.getLocalName());
    }
  }
 else {
    ComplexProperty c=(ComplexProperty)complexProperty.getParam();
    c.loadFromXml(reader,reader.getLocalName());
  }
  propertyBag.setObjectFromPropertyDefinition(this,complexProperty.getParam());
}
Program: 3920
Project: 3920
Buggy source:
/** 
 * Gets the autodiscover url.
 * @param emailAddress                   the email address
 * @param requestedServerVersion         the Exchange version
 * @param validateRedirectionUrlCallback the validate redirection url callback
 * @return the autodiscover url
 * @throws Exception the exception
 */
private URI getAutodiscoverUrl(String emailAddress,ExchangeVersion requestedServerVersion,IAutodiscoverRedirectionUrl validateRedirectionUrlCallback) throws Exception {
  AutodiscoverService autodiscoverService=new AutodiscoverService(this,requestedServerVersion);
  autodiscoverService.setRedirectionUrlValidationCallback(validateRedirectionUrlCallback);
  autodiscoverService.setEnableScpLookup(this.getEnableScpLookup());
  GetUserSettingsResponse response=autodiscoverService.getUserSettings(emailAddress,UserSettingName.InternalEwsUrl,UserSettingName.ExternalEwsUrl);
switch (response.getErrorCode()) {
case NoError:
    return this.getEwsUrlFromResponse(response,autodiscoverService.isExternal().TRUE);
case InvalidUser:
  throw new ServiceRemoteException(String.format("String_Node_Str",emailAddress));
case InvalidRequest:
throw new ServiceRemoteException(String.format("String_Node_Str",response.getErrorMessage()));
default :
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str" + "String_Node_Str",emailAddress,response.getErrorCode()));
throw new ServiceRemoteException(response.getErrorMessage());
}
}

Fixed version (ground truth):
/** 
 * Gets the autodiscover url.
 * @param emailAddress                   the email address
 * @param requestedServerVersion         the Exchange version
 * @param validateRedirectionUrlCallback the validate redirection url callback
 * @return the autodiscover url
 * @throws Exception the exception
 */
private URI getAutodiscoverUrl(String emailAddress,ExchangeVersion requestedServerVersion,IAutodiscoverRedirectionUrl validateRedirectionUrlCallback) throws Exception {
  AutodiscoverService autodiscoverService=new AutodiscoverService(this,requestedServerVersion);
  autodiscoverService.setWebProxy(getWebProxy());
  autodiscoverService.setRedirectionUrlValidationCallback(validateRedirectionUrlCallback);
  autodiscoverService.setEnableScpLookup(this.getEnableScpLookup());
  GetUserSettingsResponse response=autodiscoverService.getUserSettings(emailAddress,UserSettingName.InternalEwsUrl,UserSettingName.ExternalEwsUrl);
switch (response.getErrorCode()) {
case NoError:
    return this.getEwsUrlFromResponse(response,autodiscoverService.isExternal().TRUE);
case InvalidUser:
  throw new ServiceRemoteException(String.format("String_Node_Str",emailAddress));
case InvalidRequest:
throw new ServiceRemoteException(String.format("String_Node_Str",response.getErrorMessage()));
default :
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str" + "String_Node_Str",emailAddress,response.getErrorCode()));
throw new ServiceRemoteException(response.getErrorMessage());
}
}
Program: 3924
Project: 3924
Buggy source:
@Test public void testGetBuildVersion(){
  Assert.assertEquals("String_Node_Str","String_Node_Str",EwsUtilities.getBuildVersion());
}

Fixed version (ground truth):
@Test public void testGetBuildVersion(){
  assertEquals("String_Node_Str","String_Node_Str",EwsUtilities.getBuildVersion());
}
Program: 3925
Project: 3925
Buggy source:
@Test public void testEwsAssert(){
  EwsUtilities.EwsAssert(true,null,null);
  try {
    EwsUtilities.EwsAssert(false,"String_Node_Str","String_Node_Str");
  }
 catch (  final RuntimeException ex) {
    Assert.assertEquals("String_Node_Str",ex.getMessage());
  }
}

Fixed version (ground truth):
@Test public void testEwsAssert(){
  EwsUtilities.EwsAssert(true,null,null);
  try {
    EwsUtilities.EwsAssert(false,"String_Node_Str","String_Node_Str");
  }
 catch (  final RuntimeException ex) {
    assertEquals("String_Node_Str",ex.getMessage());
  }
}
Program: 3926
Project: 3926
Buggy source:
/** 
 * Reads attribute from XML.
 * @param writer the writer
 * @throws microsoft.exchange.webservices.data.exception.ServiceXmlSerializationException the service xml serialization exception
 */
public void writeAttributesToXml(EwsServiceXmlWriter writer) throws ServiceXmlSerializationException {
  writer.writeAttributeValue(XmlAttributeNames.BodyType,this.bodyType);
}

Fixed version (ground truth):
/** 
 * Writes attributes from XML.
 * @param writer the writer
 * @throws microsoft.exchange.webservices.data.exception.ServiceXmlSerializationException the service xml serialization exception
 */
public void writeAttributesToXml(EwsServiceXmlWriter writer) throws ServiceXmlSerializationException {
  writer.writeAttributeValue(XmlAttributeNames.BodyType,this.bodyType);
}
Program: 3927
Project: 3927
Buggy source:
/** 
 * Reads attribute from XML.
 * @param reader the reader
 * @throws javax.xml.stream.XMLStreamException the xML stream exception
 * @throws ServiceXmlDeserializationException  the service xml deserialization exception
 */
public void readTextValueFromXml(EwsServiceXmlReader reader) throws XMLStreamException, ServiceXmlDeserializationException {
  this.text=reader.readValue();
}

Fixed version (ground truth):
/** 
 * Reads attribute from XML.
 * @param reader the reader
 * @throws javax.xml.stream.XMLStreamException the xml stream exception
 * @throws ServiceXmlDeserializationException  the service xml deserialization exception
 */
public void readTextValueFromXml(EwsServiceXmlReader reader) throws XMLStreamException, ServiceXmlDeserializationException {
  this.text=reader.readValue();
}
Program: 3928
Project: 3928
Buggy source:
/** 
 * Gets an attachment.
 * @param attachments          the attachments
 * @param bodyType             the body type
 * @param additionalProperties the additional properties
 * @param errorHandling        the error handling
 * @throws Exception the exception
 */
private ServiceResponseCollection<GetAttachmentResponse> internalGetAttachments(Iterable<Attachment> attachments,BodyType bodyType,Iterable<PropertyDefinitionBase> additionalProperties,ServiceErrorHandling errorHandling) throws Exception {
  GetAttachmentRequest request=new GetAttachmentRequest(this,errorHandling);
  Iterator<Attachment> it=attachments.iterator();
  while (it.hasNext()) {
    ((ArrayList<Attachment>)request.getAttachments()).add(it.next());
  }
  request.setBodyType(bodyType);
  if (additionalProperties != null) {
    List<PropertyDefinitionBase> propsArray=new ArrayList<PropertyDefinitionBase>();
    for (    PropertyDefinitionBase propertyDefinitionBase : additionalProperties) {
      propsArray.add(propertyDefinitionBase);
    }
    request.getAdditionalProperties().addAll(propsArray);
  }
  return request.execute();
}

Fixed version (ground truth):
/** 
 * Gets an attachment.
 * @param attachments          the attachments
 * @param bodyType             the body type
 * @param additionalProperties the additional properties
 * @param errorHandling        the error handling
 * @throws Exception the exception
 */
private ServiceResponseCollection<GetAttachmentResponse> internalGetAttachments(Iterable<Attachment> attachments,BodyType bodyType,Iterable<PropertyDefinitionBase> additionalProperties,ServiceErrorHandling errorHandling) throws Exception {
  GetAttachmentRequest request=new GetAttachmentRequest(this,errorHandling);
  Iterator<Attachment> it=attachments.iterator();
  while (it.hasNext()) {
    request.getAttachments().add(it.next());
  }
  request.setBodyType(bodyType);
  if (additionalProperties != null) {
    List<PropertyDefinitionBase> propsArray=new ArrayList<PropertyDefinitionBase>();
    for (    PropertyDefinitionBase propertyDefinitionBase : additionalProperties) {
      propsArray.add(propertyDefinitionBase);
    }
    request.getAdditionalProperties().addAll(propsArray);
  }
  return request.execute();
}
Program: 3929
Project: 3929
Buggy source:
/** 
 * Loads the content of the file attachment into the specified file. Calling this method results in a call to EWS.
 * @param fileName the file name
 * @throws Exception the exception
 */
public void load(String fileName) throws Exception {
  File fileStream=new File(fileName);
  FileOutputStream fos=new FileOutputStream(fileStream);
  this.loadToStream=fos;
  try {
    this.load();
  }
  finally {
    this.loadToStream.flush();
    this.loadToStream=null;
  }
  this.fileName=fileName;
  this.content=null;
  this.contentStream=null;
}

Fixed version (ground truth):
/** 
 * Loads the content of the file attachment into the specified file. Calling this method results in a call to EWS.
 * @param fileName the file name
 * @throws Exception the exception
 */
public void load(String fileName) throws Exception {
  File fileStream=new File(fileName);
  try {
    this.loadToStream=new FileOutputStream(fileStream);
    this.load();
    this.loadToStream.flush();
  }
  finally {
    try {
      this.loadToStream.close();
    }
 catch (    Exception e) {
    }
    this.loadToStream=null;
  }
  this.fileName=fileName;
  this.content=null;
  this.contentStream=null;
}
Program: 3930
Project: 3930
Buggy source:
/** 
 * Sets the recurrence.
 * @param value the new recurrence
 * @throws Exception the exception
 */
public void setRecurrence(Recurrence value) throws Exception {
  if (value != null) {
    if (value.isRegenerationPattern()) {
      throw new ServiceLocalException(Strings.RegenerationPatternsOnlyValidForTasks);
    }
  }
  this.getPropertyBag().setObjectFromPropertyDefinition(AppointmentSchema.Recurrence,value);
}

Fixed version (ground truth):
/** 
 * Sets the recurrence.
 * @param value the new recurrence
 * @throws Exception the exception
 */
public void setRecurrence(Recurrence value) throws Exception {
  if (value != null) {
    if (value.isRegenerationPattern()) {
      throw new ServiceLocalException("String_Node_Str");
    }
  }
  this.getPropertyBag().setObjectFromPropertyDefinition(AppointmentSchema.Recurrence,value);
}
Program: 3931
Project: 3931
Buggy source:
/** 
 * Validates this instance.
 * @throws Exception
 */
@Override protected void validate() throws Exception {
  super.validate();
  if ((this.getService().getRequestedServerVersion() == ExchangeVersion.Exchange2007_SP1) && !(this.getService().getExchange2007CompatibilityMode())) {
    if (this.getPropertyBag().isPropertyUpdated(AppointmentSchema.Start) || this.getPropertyBag().isPropertyUpdated(AppointmentSchema.End) || this.getPropertyBag().isPropertyUpdated(AppointmentSchema.IsAllDayEvent)|| this.getPropertyBag().isPropertyUpdated(AppointmentSchema.Recurrence)) {
      if (!this.getPropertyBag().contains(AppointmentSchema.StartTimeZone)) {
        throw new ServiceLocalException(Strings.StartTimeZoneRequired);
      }
      this.setStartTimeZone(this.getStartTimeZone());
    }
  }
}

Fixed version (ground truth):
/** 
 * Validates this instance.
 * @throws Exception
 */
@Override protected void validate() throws Exception {
  super.validate();
  if ((this.getService().getRequestedServerVersion() == ExchangeVersion.Exchange2007_SP1) && !(this.getService().getExchange2007CompatibilityMode())) {
    if (this.getPropertyBag().isPropertyUpdated(AppointmentSchema.Start) || this.getPropertyBag().isPropertyUpdated(AppointmentSchema.End) || this.getPropertyBag().isPropertyUpdated(AppointmentSchema.IsAllDayEvent)|| this.getPropertyBag().isPropertyUpdated(AppointmentSchema.Recurrence)) {
      if (!this.getPropertyBag().contains(AppointmentSchema.StartTimeZone)) {
        throw new ServiceLocalException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
      }
      this.setStartTimeZone(this.getStartTimeZone());
    }
  }
}
Program: 3932
Project: 3932
Buggy source:
/** 
 * Sets the occurrence index.
 * @param occurrenceIndex the new occurrence index
 */
public void setOccurrenceIndex(int occurrenceIndex){
  if (occurrenceIndex < 1) {
    throw new IllegalArgumentException(Strings.OccurrenceIndexMustBeGreaterThanZero);
  }
  this.occurrenceIndex=occurrenceIndex;
}

Fixed version (ground truth):
/** 
 * Sets the occurrence index.
 * @param occurrenceIndex the new occurrence index
 */
public void setOccurrenceIndex(int occurrenceIndex){
  if (occurrenceIndex < 1) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.occurrenceIndex=occurrenceIndex;
}
Program: 3933
Project: 3933
Buggy source:
public static <T extends SimpleServiceRequestBase>T extractServiceRequest(ExchangeService exchangeService,Future<?> asyncResult) throws Exception {
  EwsUtilities.validateParam(asyncResult,"String_Node_Str");
  AsyncRequestResult asyncRequestResult=(AsyncRequestResult)asyncResult;
  if (asyncRequestResult == null) {
    throw new ArgumentException(Strings.InvalidAsyncResult,"String_Node_Str");
  }
  if (asyncRequestResult.serviceRequest == null) {
    throw new ArgumentException(Strings.InvalidAsyncResult,"String_Node_Str");
  }
  if (!asyncRequestResult.serviceRequest.getService().equals(exchangeService)) {
    throw new ArgumentException(Strings.InvalidAsyncResult,"String_Node_Str");
  }
  T serviceRequest=(T)asyncRequestResult.getServiceRequest();
  if (serviceRequest == null) {
    throw new ArgumentException(Strings.InvalidAsyncResult,"String_Node_Str");
  }
  return serviceRequest;
}

Fixed version (ground truth):
public static <T extends SimpleServiceRequestBase>T extractServiceRequest(ExchangeService exchangeService,Future<?> asyncResult) throws Exception {
  EwsUtilities.validateParam(asyncResult,"String_Node_Str");
  AsyncRequestResult asyncRequestResult=(AsyncRequestResult)asyncResult;
  if (asyncRequestResult == null) {
    throw new ArgumentException("String_Node_Str","String_Node_Str");
  }
  if (asyncRequestResult.serviceRequest == null) {
    throw new ArgumentException("String_Node_Str","String_Node_Str");
  }
  if (!asyncRequestResult.serviceRequest.getService().equals(exchangeService)) {
    throw new ArgumentException("String_Node_Str","String_Node_Str");
  }
  T serviceRequest=(T)asyncRequestResult.getServiceRequest();
  if (serviceRequest == null) {
    throw new ArgumentException("String_Node_Str","String_Node_Str");
  }
  return serviceRequest;
}
Program: 3934
Project: 3934
Buggy source:
/** 
 * Throws exception if this is not a new service object.
 */
protected void throwIfThisIsNotNew(){
  if (!this.isNew()) {
    throw new UnsupportedOperationException(Strings.AttachmentCannotBeUpdated);
  }
}

Fixed version (ground truth):
/** 
 * Throws exception if this is not a new service object.
 */
protected void throwIfThisIsNotNew(){
  if (!this.isNew()) {
    throw new UnsupportedOperationException("String_Node_Str");
  }
}
Program: 3935
Project: 3935
Buggy source:
/** 
 * Calls the DeleteAttachment web method to delete a list of attachments.
 * @param attachments the attachments
 * @throws Exception the exception
 */
private void internalDeleteAttachments(Iterable<Attachment> attachments) throws Exception {
  ServiceResponseCollection<DeleteAttachmentResponse> responses=this.owner.getService().deleteAttachments(attachments);
  Enumeration<DeleteAttachmentResponse> enumerator=responses.getEnumerator();
  while (enumerator.hasMoreElements()) {
    DeleteAttachmentResponse response=enumerator.nextElement();
    if (response.getResult() != ServiceResult.Error) {
      this.removeFromChangeLog(response.getAttachment());
    }
  }
  if (responses.getOverallResult() == ServiceResult.Error) {
    throw new DeleteAttachmentException(responses,Strings.AtLeastOneAttachmentCouldNotBeDeleted);
  }
}

Fixed version (ground truth):
/** 
 * Calls the DeleteAttachment web method to delete a list of attachments.
 * @param attachments the attachments
 * @throws Exception the exception
 */
private void internalDeleteAttachments(Iterable<Attachment> attachments) throws Exception {
  ServiceResponseCollection<DeleteAttachmentResponse> responses=this.owner.getService().deleteAttachments(attachments);
  Enumeration<DeleteAttachmentResponse> enumerator=responses.getEnumerator();
  while (enumerator.hasMoreElements()) {
    DeleteAttachmentResponse response=enumerator.nextElement();
    if (response.getResult() != ServiceResult.Error) {
      this.removeFromChangeLog(response.getAttachment());
    }
  }
  if (responses.getOverallResult() == ServiceResult.Error) {
    throw new DeleteAttachmentException(responses,"String_Node_Str");
  }
}
Program: 3936
Project: 3936
Buggy source:
/** 
 * Calls the CreateAttachment web method to create a list of attachments.
 * @param parentItemId the parent item id
 * @param attachments  the attachments
 * @throws Exception the exception
 */
private void internalCreateAttachments(String parentItemId,Iterable<Attachment> attachments) throws Exception {
  ServiceResponseCollection<CreateAttachmentResponse> responses=this.owner.getService().createAttachments(parentItemId,attachments);
  Enumeration<CreateAttachmentResponse> enumerator=responses.getEnumerator();
  while (enumerator.hasMoreElements()) {
    CreateAttachmentResponse response=enumerator.nextElement();
    if (response.getResult() != ServiceResult.Error) {
      this.removeFromChangeLog(response.getAttachment());
    }
  }
  if (responses.getOverallResult() == ServiceResult.Error) {
    throw new CreateAttachmentException(responses,Strings.AttachmentCreationFailed);
  }
}

Fixed version (ground truth):
/** 
 * Calls the CreateAttachment web method to create a list of attachments.
 * @param parentItemId the parent item id
 * @param attachments  the attachments
 * @throws Exception the exception
 */
private void internalCreateAttachments(String parentItemId,Iterable<Attachment> attachments) throws Exception {
  ServiceResponseCollection<CreateAttachmentResponse> responses=this.owner.getService().createAttachments(parentItemId,attachments);
  Enumeration<CreateAttachmentResponse> enumerator=responses.getEnumerator();
  while (enumerator.hasMoreElements()) {
    CreateAttachmentResponse response=enumerator.nextElement();
    if (response.getResult() != ServiceResult.Error) {
      this.removeFromChangeLog(response.getAttachment());
    }
  }
  if (responses.getOverallResult() == ServiceResult.Error) {
    throw new CreateAttachmentException(responses,"String_Node_Str");
  }
}
Program: 3937
Project: 3937
Buggy source:
/** 
 * Removes the attachment at the specified index.
 * @param index Index of the attachment to remove.
 */
public void removeAt(int index){
  if (index < 0 || index >= this.getCount()) {
    throw new IllegalArgumentException("String_Node_Str" + Strings.IndexIsOutOfRange);
  }
  this.internalRemoveAt(index);
}

Fixed version (ground truth):
/** 
 * Removes the attachment at the specified index.
 * @param index Index of the attachment to remove.
 */
public void removeAt(int index){
  if (index < 0 || index >= this.getCount()) {
    throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str");
  }
  this.internalRemoveAt(index);
}
Program: 3938
Project: 3938
Buggy source:
/** 
 * Validates this instance.
 * @throws Exception the exception
 */
public void validate() throws Exception {
  if (this.owner.isNew() && this.owner.getService().getRequestedServerVersion().ordinal() >= ExchangeVersion.Exchange2010_SP2.ordinal()) {
    boolean contactPhotoFound=false;
    for (int attachmentIndex=0; attachmentIndex < this.getAddedItems().size(); attachmentIndex++) {
      final Attachment attachment=this.getAddedItems().get(attachmentIndex);
      if (attachment != null && attachment.isNew() && attachment instanceof FileAttachment) {
        if (((FileAttachment)attachment).isContactPhoto()) {
          if (contactPhotoFound) {
            throw new ServiceValidationException(Strings.MultipleContactPhotosInAttachment);
          }
          contactPhotoFound=true;
        }
      }
      attachment.validate(attachmentIndex);
    }
  }
}

Fixed version (ground truth):
/** 
 * Validates this instance.
 * @throws Exception the exception
 */
public void validate() throws Exception {
  if (this.owner.isNew() && this.owner.getService().getRequestedServerVersion().ordinal() >= ExchangeVersion.Exchange2010_SP2.ordinal()) {
    boolean contactPhotoFound=false;
    for (int attachmentIndex=0; attachmentIndex < this.getAddedItems().size(); attachmentIndex++) {
      final Attachment attachment=this.getAddedItems().get(attachmentIndex);
      if (attachment != null && attachment.isNew() && attachment instanceof FileAttachment) {
        if (((FileAttachment)attachment).isContactPhoto()) {
          if (contactPhotoFound) {
            throw new ServiceValidationException("String_Node_Str");
          }
          contactPhotoFound=true;
        }
      }
      attachment.validate(attachmentIndex);
    }
  }
}
Program: 3939
Project: 3939
Buggy source:
/** 
 * Removes an attendee from the collection.
 * @param index the index
 */
public void removeAt(int index){
  if (index < 0 || index >= this.getCount()) {
    throw new IllegalArgumentException("String_Node_Str" + Strings.IndexIsOutOfRange);
  }
  this.internalRemoveAt(index);
}

Fixed version (ground truth):
/** 
 * Removes an attendee from the collection.
 * @param index the index
 */
public void removeAt(int index){
  if (index < 0 || index >= this.getCount()) {
    throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str");
  }
  this.internalRemoveAt(index);
}
Program: 3942
Project: 3942
Buggy source:
/** 
 * Retrieves the specified settings for a set of users.
 * @param userSmtpAddresses the user smtp addresses
 * @param userSettingNames  The user setting names.
 * @return A GetUserSettingsResponseCollection object containing theresponses for each individual user.
 * @throws Exception the exception
 */
public GetUserSettingsResponseCollection getUsersSettings(Iterable<String> userSmtpAddresses,UserSettingName... userSettingNames) throws Exception {
  if (this.getRequestedServerVersion().compareTo(MinimumRequestVersionForAutoDiscoverSoapService) < 0) {
    throw new ServiceVersionException(String.format(Strings.AutodiscoverServiceIncompatibleWithRequestVersion,MinimumRequestVersionForAutoDiscoverSoapService));
  }
  List<String> smtpAddresses=new ArrayList<String>();
  smtpAddresses.addAll((Collection<? extends String>)userSmtpAddresses);
  List<UserSettingName> settings=new ArrayList<UserSettingName>();
  settings.addAll(Arrays.asList(userSettingNames));
  return this.getUserSettings(smtpAddresses,settings);
}

Fixed version (ground truth):
/** 
 * Retrieves the specified settings for a set of users.
 * @param userSmtpAddresses the user smtp addresses
 * @param userSettingNames  The user setting names.
 * @return A GetUserSettingsResponseCollection object containing theresponses for each individual user.
 * @throws Exception the exception
 */
public GetUserSettingsResponseCollection getUsersSettings(Iterable<String> userSmtpAddresses,UserSettingName... userSettingNames) throws Exception {
  if (this.getRequestedServerVersion().compareTo(MinimumRequestVersionForAutoDiscoverSoapService) < 0) {
    throw new ServiceVersionException(String.format("String_Node_Str",MinimumRequestVersionForAutoDiscoverSoapService));
  }
  List<String> smtpAddresses=new ArrayList<String>();
  smtpAddresses.addAll((Collection<? extends String>)userSmtpAddresses);
  List<UserSettingName> settings=new ArrayList<UserSettingName>();
  settings.addAll(Arrays.asList(userSettingNames));
  return this.getUserSettings(smtpAddresses,settings);
}
Program: 3943
Project: 3943
Buggy source:
/** 
 * Gets the autodiscover endpoint URL.
 * @param host The host.
 * @return URI The URI.
 * @throws Exception the exception
 */
private URI getAutodiscoverEndpointUrl(String host) throws Exception {
  URI autodiscoverUrl=null;
  OutParam<URI> outParam=new OutParam<URI>();
  if (this.tryGetAutodiscoverEndpointUrl(host,outParam)) {
    return autodiscoverUrl;
  }
 else {
    throw new AutodiscoverLocalException(Strings.NoSoapOrWsSecurityEndpointAvailable);
  }
}

Fixed version (ground truth):
/** 
 * Gets the autodiscover endpoint URL.
 * @param host The host.
 * @return URI The URI.
 * @throws Exception the exception
 */
private URI getAutodiscoverEndpointUrl(String host) throws Exception {
  URI autodiscoverUrl=null;
  OutParam<URI> outParam=new OutParam<URI>();
  if (this.tryGetAutodiscoverEndpointUrl(host,outParam)) {
    return autodiscoverUrl;
  }
 else {
    throw new AutodiscoverLocalException("String_Node_Str");
  }
}
Program: 3944
Project: 3944
Buggy source:
/** 
 * Default implementation of AutodiscoverRedirectionUrlValidationCallback. Always returns true indicating that the URL can be used.
 * @param redirectionUrl the redirection url
 * @return Returns true.
 * @throws AutodiscoverLocalException the autodiscover local exception
 */
private boolean defaultAutodiscoverRedirectionUrlValidationCallback(String redirectionUrl) throws AutodiscoverLocalException {
  throw new AutodiscoverLocalException(String.format(Strings.AutodiscoverRedirectBlocked,redirectionUrl));
}

Fixed version (ground truth):
/** 
 * Default implementation of AutodiscoverRedirectionUrlValidationCallback. Always returns true indicating that the URL can be used.
 * @param redirectionUrl the redirection url
 * @return Returns true.
 * @throws AutodiscoverLocalException the autodiscover local exception
 */
private boolean defaultAutodiscoverRedirectionUrlValidationCallback(String redirectionUrl) throws AutodiscoverLocalException {
  throw new AutodiscoverLocalException(String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str",redirectionUrl));
}
Program: 3945
Project: 3945
Buggy source:
/** 
 * Gets settings for one or more users.
 * @param smtpAddresses    The SMTP addresses of the users.
 * @param settings         The settings.
 * @param requestedVersion Requested version of the Exchange service.
 * @param autodiscoverUrl  The autodiscover URL.
 * @return GetUserSettingsResponse collection.
 * @throws ServiceLocalException the service local exception
 * @throws Exception             the exception
 */
private GetUserSettingsResponseCollection internalGetUserSettings(List<String> smtpAddresses,List<UserSettingName> settings,ExchangeVersion requestedVersion,URI autodiscoverUrl) throws ServiceLocalException, Exception {
  for (int currentHop=0; currentHop < AutodiscoverService.AutodiscoverMaxRedirections; currentHop++) {
    GetUserSettingsRequest request=new GetUserSettingsRequest(this,autodiscoverUrl);
    request.setSmtpAddresses(smtpAddresses);
    request.setSettings(settings);
    GetUserSettingsResponseCollection response=request.execute();
    if (response.getErrorCode() == AutodiscoverErrorCode.RedirectUrl && response.getRedirectionUrl() != null) {
      this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",autodiscoverUrl.toString(),response.getRedirectionUrl()));
      autodiscoverUrl=response.getRedirectionUrl();
    }
 else {
      return response;
    }
  }
  this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",AutodiscoverMaxRedirections));
  throw new AutodiscoverLocalException(Strings.MaximumRedirectionHopsExceeded);
}

Fixed version (ground truth):
/** 
 * Gets settings for one or more users.
 * @param smtpAddresses    The SMTP addresses of the users.
 * @param settings         The settings.
 * @param requestedVersion Requested version of the Exchange service.
 * @param autodiscoverUrl  The autodiscover URL.
 * @return GetUserSettingsResponse collection.
 * @throws ServiceLocalException the service local exception
 * @throws Exception             the exception
 */
private GetUserSettingsResponseCollection internalGetUserSettings(List<String> smtpAddresses,List<UserSettingName> settings,ExchangeVersion requestedVersion,URI autodiscoverUrl) throws ServiceLocalException, Exception {
  for (int currentHop=0; currentHop < AutodiscoverService.AutodiscoverMaxRedirections; currentHop++) {
    GetUserSettingsRequest request=new GetUserSettingsRequest(this,autodiscoverUrl);
    request.setSmtpAddresses(smtpAddresses);
    request.setSettings(settings);
    GetUserSettingsResponseCollection response=request.execute();
    if (response.getErrorCode() == AutodiscoverErrorCode.RedirectUrl && response.getRedirectionUrl() != null) {
      this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",autodiscoverUrl.toString(),response.getRedirectionUrl()));
      autodiscoverUrl=response.getRedirectionUrl();
    }
 else {
      return response;
    }
  }
  this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",AutodiscoverMaxRedirections));
  throw new MaximumRedirectionHopsExceededException();
}
Program: 3946
Project: 3946
Buggy source:
/** 
 * Retrieves the specified settings for single SMTP address.
 * @param userSmtpAddress  The SMTP addresses of the user.
 * @param userSettingNames The user setting names.
 * @return A UserResponse object containing the requested settings for thespecified user.
 * @throws Exception the exception<p/> This method handles will run the entire Autodiscover "discovery" algorithm and will follow address and URL redirections.
 */
public GetUserSettingsResponse getUserSettings(String userSmtpAddress,UserSettingName... userSettingNames) throws Exception {
  List<UserSettingName> requestedSettings=new ArrayList<UserSettingName>();
  requestedSettings.addAll(Arrays.asList(userSettingNames));
  if (userSmtpAddress == null || userSmtpAddress.isEmpty()) {
    throw new ServiceValidationException(Strings.InvalidAutodiscoverSmtpAddress);
  }
  if (requestedSettings.size() == 0) {
    throw new ServiceValidationException(Strings.InvalidAutodiscoverSettingsCount);
  }
  if (this.getRequestedServerVersion().compareTo(MinimumRequestVersionForAutoDiscoverSoapService) < 0) {
    return this.internalGetLegacyUserSettings(userSmtpAddress,requestedSettings);
  }
 else {
    return this.internalGetSoapUserSettings(userSmtpAddress,requestedSettings);
  }
}

Fixed version (ground truth):
/** 
 * Retrieves the specified settings for single SMTP address.
 * @param userSmtpAddress  The SMTP addresses of the user.
 * @param userSettingNames The user setting names.
 * @return A UserResponse object containing the requested settings for thespecified user.
 * @throws Exception the exception<p/> This method handles will run the entire Autodiscover "discovery" algorithm and will follow address and URL redirections.
 */
public GetUserSettingsResponse getUserSettings(String userSmtpAddress,UserSettingName... userSettingNames) throws Exception {
  List<UserSettingName> requestedSettings=new ArrayList<UserSettingName>();
  requestedSettings.addAll(Arrays.asList(userSettingNames));
  if (userSmtpAddress == null || userSmtpAddress.isEmpty()) {
    throw new ServiceValidationException("String_Node_Str");
  }
  if (requestedSettings.size() == 0) {
    throw new ServiceValidationException("String_Node_Str");
  }
  if (this.getRequestedServerVersion().compareTo(MinimumRequestVersionForAutoDiscoverSoapService) < 0) {
    return this.internalGetLegacyUserSettings(userSmtpAddress,requestedSettings);
  }
 else {
    return this.internalGetSoapUserSettings(userSmtpAddress,requestedSettings);
  }
}
Program: 3949
Project: 3949
Buggy source:
/** 
 * Calls the SOAP Autodiscover service for user settings for a single SMTP address.
 * @param smtpAddress       SMTP address.
 * @param requestedSettings The requested settings.
 * @return GetUserSettingsResponse
 */
protected GetUserSettingsResponse internalGetSoapUserSettings(String smtpAddress,List<UserSettingName> requestedSettings) throws Exception {
  List<String> smtpAddresses=new ArrayList<String>();
  smtpAddresses.add(smtpAddress);
  List<String> redirectionEmailAddresses=new ArrayList<String>();
  redirectionEmailAddresses.add(smtpAddress.toLowerCase());
  for (int currentHop=0; currentHop < AutodiscoverService.AutodiscoverMaxRedirections; currentHop++) {
    GetUserSettingsResponse response=this.getUserSettings(smtpAddresses,requestedSettings).getTResponseAtIndex(0);
switch (response.getErrorCode()) {
case RedirectAddress:
      this.traceMessage(TraceFlags.AutodiscoverResponse,String.format("String_Node_Str",response.getRedirectTarget()));
    smtpAddresses.clear();
  smtpAddresses.add(response.getRedirectTarget().toLowerCase());
this.url=null;
this.domain=null;
this.disableScpLookupIfDuplicateRedirection(response.getRedirectTarget(),redirectionEmailAddresses);
break;
case RedirectUrl:
this.traceMessage(TraceFlags.AutodiscoverResponse,String.format("String_Node_Str",response.getRedirectTarget()));
this.url=this.getCredentials().adjustUrl(new URI(response.getRedirectTarget()));
break;
case NoError:
default :
return response;
}
}
throw new AutodiscoverLocalException(Strings.AutodiscoverCouldNotBeLocated);
}

Fixed version (ground truth):
/** 
 * Calls the SOAP Autodiscover service for user settings for a single SMTP address.
 * @param smtpAddress       SMTP address.
 * @param requestedSettings The requested settings.
 * @return GetUserSettingsResponse
 */
protected GetUserSettingsResponse internalGetSoapUserSettings(String smtpAddress,List<UserSettingName> requestedSettings) throws Exception {
  List<String> smtpAddresses=new ArrayList<String>();
  smtpAddresses.add(smtpAddress);
  List<String> redirectionEmailAddresses=new ArrayList<String>();
  redirectionEmailAddresses.add(smtpAddress.toLowerCase());
  for (int currentHop=0; currentHop < AutodiscoverService.AutodiscoverMaxRedirections; currentHop++) {
    GetUserSettingsResponse response=this.getUserSettings(smtpAddresses,requestedSettings).getTResponseAtIndex(0);
switch (response.getErrorCode()) {
case RedirectAddress:
      this.traceMessage(TraceFlags.AutodiscoverResponse,String.format("String_Node_Str",response.getRedirectTarget()));
    smtpAddresses.clear();
  smtpAddresses.add(response.getRedirectTarget().toLowerCase());
this.url=null;
this.domain=null;
this.disableScpLookupIfDuplicateRedirection(response.getRedirectTarget(),redirectionEmailAddresses);
break;
case RedirectUrl:
this.traceMessage(TraceFlags.AutodiscoverResponse,String.format("String_Node_Str",response.getRedirectTarget()));
this.url=this.getCredentials().adjustUrl(new URI(response.getRedirectTarget()));
break;
case NoError:
default :
return response;
}
}
throw new AutodiscoverLocalException("String_Node_Str");
}
Program: 3950
Project: 3950
Buggy source:
/** 
 * Gets settings for one or more domains.
 * @param domains          The domains.
 * @param settings         The settings.
 * @param requestedVersion Requested version of the Exchange service.
 * @param autodiscoverUrl  The autodiscover URL.
 * @return GetDomainSettingsResponse Collection.
 * @throws ServiceLocalException the service local exception
 * @throws Exception             the exception
 */
private GetDomainSettingsResponseCollection internalGetDomainSettings(List<String> domains,List<DomainSettingName> settings,ExchangeVersion requestedVersion,URI autodiscoverUrl) throws ServiceLocalException, Exception {
  for (int currentHop=0; currentHop < AutodiscoverService.AutodiscoverMaxRedirections; currentHop++) {
    GetDomainSettingsRequest request=new GetDomainSettingsRequest(this,autodiscoverUrl);
    request.setDomains(domains);
    request.setSettings(settings);
    request.setRequestedVersion(requestedVersion);
    GetDomainSettingsResponseCollection response=request.execute();
    if (response.getErrorCode() == AutodiscoverErrorCode.RedirectUrl && response.getRedirectionUrl() != null) {
      autodiscoverUrl=response.getRedirectionUrl();
    }
 else {
      return response;
    }
  }
  this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",AutodiscoverMaxRedirections));
  throw new AutodiscoverLocalException(Strings.MaximumRedirectionHopsExceeded);
}

Fixed version (ground truth):
/** 
 * Gets settings for one or more domains.
 * @param domains          The domains.
 * @param settings         The settings.
 * @param requestedVersion Requested version of the Exchange service.
 * @param autodiscoverUrl  The autodiscover URL.
 * @return GetDomainSettingsResponse Collection.
 * @throws ServiceLocalException the service local exception
 * @throws Exception             the exception
 */
private GetDomainSettingsResponseCollection internalGetDomainSettings(List<String> domains,List<DomainSettingName> settings,ExchangeVersion requestedVersion,URI autodiscoverUrl) throws ServiceLocalException, Exception {
  for (int currentHop=0; currentHop < AutodiscoverService.AutodiscoverMaxRedirections; currentHop++) {
    GetDomainSettingsRequest request=new GetDomainSettingsRequest(this,autodiscoverUrl);
    request.setDomains(domains);
    request.setSettings(settings);
    request.setRequestedVersion(requestedVersion);
    GetDomainSettingsResponseCollection response=request.execute();
    if (response.getErrorCode() == AutodiscoverErrorCode.RedirectUrl && response.getRedirectionUrl() != null) {
      autodiscoverUrl=response.getRedirectionUrl();
    }
 else {
      return response;
    }
  }
  this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",AutodiscoverMaxRedirections));
  throw new MaximumRedirectionHopsExceededException();
}
Program: 3951
Project: 3951
Buggy source:
/** 
 * Gets user settings from Autodiscover legacy endpoint.
 * @param emailAddress      The email address to use.
 * @param requestedSettings The requested settings.
 * @return GetUserSettingsResponse
 */
protected GetUserSettingsResponse internalGetLegacyUserSettings(String emailAddress,List<UserSettingName> requestedSettings) throws Exception {
  if ((this.getCredentials() != null) && (this.getCredentials() instanceof WSSecurityBasedCredentials)) {
    throw new AutodiscoverLocalException(Strings.WLIDCredentialsCannotBeUsedWithLegacyAutodiscover);
  }
  OutlookConfigurationSettings settings=this.getLegacyUserSettings(OutlookConfigurationSettings.class,emailAddress);
  return settings.convertSettings(emailAddress,requestedSettings);
}

Fixed version (ground truth):
/** 
 * Gets user settings from Autodiscover legacy endpoint.
 * @param emailAddress      The email address to use.
 * @param requestedSettings The requested settings.
 * @return GetUserSettingsResponse
 */
protected GetUserSettingsResponse internalGetLegacyUserSettings(String emailAddress,List<UserSettingName> requestedSettings) throws Exception {
  if ((this.getCredentials() != null) && (this.getCredentials() instanceof WSSecurityBasedCredentials)) {
    throw new AutodiscoverLocalException("String_Node_Str");
  }
  OutlookConfigurationSettings settings=this.getLegacyUserSettings(OutlookConfigurationSettings.class,emailAddress);
  return settings.convertSettings(emailAddress,requestedSettings);
}
Program: 3952
Project: 3952
Buggy source:
/** 
 * This method doesn't handle 500 ISE errors. This is handled by the caller since 500 ISE typically indicates that a SOAP fault has occurred and the handling of a SOAP fault is currently service specific.
 * @throws Exception
 */
protected void internalProcessHttpErrorResponse(HttpWebRequest httpWebResponse,Exception webException,TraceFlags responseHeadersTraceFlag,TraceFlags responseTraceFlag) throws Exception {
  EwsUtilities.EwsAssert(500 != httpWebResponse.getResponseCode(),"String_Node_Str","String_Node_Str");
  this.processHttpResponseHeaders(responseHeadersTraceFlag,httpWebResponse);
  if (httpWebResponse.getResponseCode() == 456) {
    String location=httpWebResponse.getResponseContentType();
    URI accountUnlockUrl=null;
    if (checkURIPath(location)) {
      accountUnlockUrl=new URI(location);
    }
    this.traceMessage(responseTraceFlag,String.format("String_Node_Str",accountUnlockUrl));
    throw new AccountIsLockedException(String.format(Strings.AccountIsLocked,accountUnlockUrl),accountUnlockUrl,webException);
  }
}

Fixed version (ground truth):
/** 
 * This method doesn't handle 500 ISE errors. This is handled by the caller since 500 ISE typically indicates that a SOAP fault has occurred and the handling of a SOAP fault is currently service specific.
 * @throws Exception
 */
protected void internalProcessHttpErrorResponse(HttpWebRequest httpWebResponse,Exception webException,TraceFlags responseHeadersTraceFlag,TraceFlags responseTraceFlag) throws Exception {
  EwsUtilities.EwsAssert(500 != httpWebResponse.getResponseCode(),"String_Node_Str","String_Node_Str");
  this.processHttpResponseHeaders(responseHeadersTraceFlag,httpWebResponse);
  if (httpWebResponse.getResponseCode() == 456) {
    String location=httpWebResponse.getResponseContentType();
    URI accountUnlockUrl=null;
    if (checkURIPath(location)) {
      accountUnlockUrl=new URI(location);
    }
    final String message=String.format(Strings.AccountIsLocked,accountUnlockUrl);
    this.traceMessage(responseTraceFlag,message);
    throw new AccountIsLockedException(message,accountUnlockUrl,webException);
  }
}