nus-yam/ex-repair huggingface dataset:
Program: 13957
Project: 13957
Buggy source:
/** 
 * Get the time zone by Java TimeZone. <p> DateTimeZone only accepts a subset of the IDs from TimeZone. The excluded IDs are the short three letter form (except UTC). This  method will attempt to convert between time zones created using the short IDs and the full version.
 * @param zone  the zone to convert, null means default
 * @return the DateTimeZone object for the zone
 * @throws IllegalArgumentException if the zone is not recognised
 */
public static DateTimeZone getInstance(java.util.TimeZone zone){
  if (zone == null) {
    return getDefault();
  }
  final String id=zone.getID();
  if (id.equals("String_Node_Str")) {
    return DateTimeZone.UTC;
  }
  DateTimeZone dtz=null;
  String convId=getConvertedId(id);
  if (convId != null) {
    dtz=cProvider.getZone(convId);
  }
  if (dtz == null) {
    dtz=cProvider.getZone(id);
  }
  if (dtz != null) {
    return dtz;
  }
  if (convId == null) {
    convId=zone.getDisplayName();
    if (convId.startsWith("String_Node_Str") || convId.startsWith("String_Node_Str")) {
      convId=convId.substring(3);
      int offset=-(int)offsetFormatter().parseMillis(convId,ISOChronology.getInstance(UTC));
      if (offset == 0L) {
        return DateTimeZone.UTC;
      }
 else {
        convId=printTimeZone(offset);
        return fixedOffsetZone(convId,offset);
      }
    }
  }
  throw new IllegalArgumentException("String_Node_Str" + id);
}

Fixed version (ground truth):
/** 
 * Get the time zone by Java TimeZone. <p> DateTimeZone only accepts a subset of the IDs from TimeZone. The excluded IDs are the short three letter form (except UTC). This  method will attempt to convert between time zones created using the short IDs and the full version.
 * @param zone  the zone to convert, null means default
 * @return the DateTimeZone object for the zone
 * @throws IllegalArgumentException if the zone is not recognised
 */
public static DateTimeZone getInstance(java.util.TimeZone zone){
  if (zone == null) {
    return getDefault();
  }
  final String id=zone.getID();
  if (id.equals("String_Node_Str")) {
    return DateTimeZone.UTC;
  }
  DateTimeZone dtz=null;
  String convId=getConvertedId(id);
  if (convId != null) {
    dtz=cProvider.getZone(convId);
  }
  if (dtz == null) {
    dtz=cProvider.getZone(id);
  }
  if (dtz != null) {
    return dtz;
  }
  if (convId == null) {
    convId=zone.getDisplayName();
    if (convId.startsWith("String_Node_Str") || convId.startsWith("String_Node_Str")) {
      convId=convId.substring(3);
      int offset=parseOffset(convId);
      if (offset == 0L) {
        return DateTimeZone.UTC;
      }
 else {
        convId=printOffset(offset);
        return fixedOffsetZone(convId,offset);
      }
    }
  }
  throw new IllegalArgumentException("String_Node_Str" + id);
}
Program: 13958
Project: 13958
Buggy source:
private PeriodFormat(){
  iDefault=new PeriodFormatterBuilder().appendYears().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str").appendMonths().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str").appendWeeks().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str").appendDays().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str").appendHours().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str").appendMinutes().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str").appendSeconds().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str").appendMillis().appendSuffix("String_Node_Str","String_Node_Str").toFormatter();
}

Fixed version (ground truth):
private PeriodFormat(){
  String[] variants={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
  iDefault=new PeriodFormatterBuilder().appendYears().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str",variants).appendMonths().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str",variants).appendWeeks().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str",variants).appendDays().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str",variants).appendHours().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str",variants).appendMinutes().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str",variants).appendSeconds().appendSuffix("String_Node_Str","String_Node_Str").appendSeparator("String_Node_Str","String_Node_Str",variants).appendMillis().appendSuffix("String_Node_Str","String_Node_Str").toFormatter();
}
Program: 13959
Project: 13959
Buggy source:
private PeriodFormatterBuilder appendSeparator(String text,String finalText,boolean useBefore,boolean useAfter){
  if (text == null || finalText == null) {
    throw new IllegalArgumentException();
  }
  clearPrefix();
  List formatters=iFormatters;
  if (formatters.size() == 0) {
    if (useAfter && useBefore == false) {
      formatters.add(new Separator(text,finalText,Literal.EMPTY,useBefore,useAfter));
    }
    return this;
  }
  int i;
  Separator lastSeparator=null;
  for (i=formatters.size(); --i >= 0; ) {
    if (formatters.get(i) instanceof Separator) {
      lastSeparator=(Separator)formatters.get(i);
      formatters=formatters.subList(i + 1,formatters.size());
      break;
    }
  }
  if (lastSeparator != null && formatters.size() == 0) {
    throw new IllegalStateException("String_Node_Str");
  }
 else {
    BasePeriodFormatter composite=createComposite(formatters);
    formatters.clear();
    formatters.add(new Separator(text,finalText,composite,useBefore,useAfter));
  }
  return this;
}

Fixed version (ground truth):
private PeriodFormatterBuilder appendSeparator(String text,String finalText,String[] variants,boolean useBefore,boolean useAfter){
  if (text == null || finalText == null) {
    throw new IllegalArgumentException();
  }
  clearPrefix();
  List formatters=iFormatters;
  if (formatters.size() == 0) {
    if (useAfter && useBefore == false) {
      formatters.add(new Separator(text,finalText,variants,Literal.EMPTY,useBefore,useAfter));
    }
    return this;
  }
  int i;
  Separator lastSeparator=null;
  for (i=formatters.size(); --i >= 0; ) {
    if (formatters.get(i) instanceof Separator) {
      lastSeparator=(Separator)formatters.get(i);
      formatters=formatters.subList(i + 1,formatters.size());
      break;
    }
  }
  if (lastSeparator != null && formatters.size() == 0) {
    throw new IllegalStateException("String_Node_Str");
  }
 else {
    BasePeriodFormatter composite=createComposite(formatters);
    formatters.clear();
    formatters.add(new Separator(text,finalText,variants,composite,useBefore,useAfter));
  }
  return this;
}
Program: 13960
Project: 13960
Buggy source:
/** 
 * Append a separator, which is output only if fields are printed before the separator. <p> For example, <code>builder.appendDays().appendSeparator(",").appendHours()</code> will only output the comma if the days fields is output. <p> The text will be parsed case-insensitively. <p> Note: appending a separator discontinues any further work on the latest appended field.
 * @param text  the text to use as a separator
 * @return this PeriodFormatterBuilder
 * @throws IllegalStateException if this separator follows a previous one
 */
public PeriodFormatterBuilder appendSeparatorIfFieldsBefore(String text){
  return appendSeparator(text,text,true,false);
}

Fixed version (ground truth):
/** 
 * Append a separator, which is output only if fields are printed before the separator. <p> For example, <code>builder.appendDays().appendSeparatorIfFieldsBefore(",").appendHours()</code> will only output the comma if the days fields is output. <p> The text will be parsed case-insensitively. <p> Note: appending a separator discontinues any further work on the latest appended field.
 * @param text  the text to use as a separator
 * @return this PeriodFormatterBuilder
 * @throws IllegalStateException if this separator follows a previous one
 */
public PeriodFormatterBuilder appendSeparatorIfFieldsBefore(String text){
  return appendSeparator(text,text,null,true,false);
}
Program: 13961
Project: 13961
Buggy source:
/** 
 * Append a separator, which is output only if fields are printed after the separator. <p> For example, <code>builder.appendDays().appendSeparator(",").appendHours()</code> will only output the comma if the hours fields is output. <p> The text will be parsed case-insensitively. <p> Note: appending a separator discontinues any further work on the latest appended field.
 * @param text  the text to use as a separator
 * @return this PeriodFormatterBuilder
 * @throws IllegalStateException if this separator follows a previous one
 */
public PeriodFormatterBuilder appendSeparatorIfFieldsAfter(String text){
  return appendSeparator(text,text,false,true);
}

Fixed version (ground truth):
/** 
 * Append a separator, which is output only if fields are printed after the separator. <p> For example, <code>builder.appendDays().appendSeparatorIfFieldsAfter(",").appendHours()</code> will only output the comma if the hours fields is output. <p> The text will be parsed case-insensitively. <p> Note: appending a separator discontinues any further work on the latest appended field.
 * @param text  the text to use as a separator
 * @return this PeriodFormatterBuilder
 * @throws IllegalStateException if this separator follows a previous one
 */
public PeriodFormatterBuilder appendSeparatorIfFieldsAfter(String text){
  return appendSeparator(text,text,null,false,true);
}
Program: 13962
Project: 13962
Buggy source:
Separator(String text,String finalText,BasePeriodFormatter before,boolean useBefore,boolean useAfter){
  iText=text;
  iFinalText=finalText;
  iBefore=before;
  iUseBefore=useBefore;
  iUseAfter=useAfter;
}

Fixed version (ground truth):
Separator(String text,String finalText,String[] variants,BasePeriodFormatter before,boolean useBefore,boolean useAfter){
  iText=text;
  iFinalText=finalText;
  if ((finalText == null || text.equals(finalText)) && (variants == null || variants.length == 0)) {
    iParsedForms=new String[]{text};
  }
 else {
    TreeSet parsedSet=new TreeSet(String.CASE_INSENSITIVE_ORDER);
    parsedSet.add(text);
    parsedSet.add(finalText);
    if (variants != null) {
      for (int i=variants.length; --i >= 0; ) {
        parsedSet.add(variants[i]);
      }
    }
    ArrayList parsedList=new ArrayList(parsedSet);
    Collections.reverse(parsedList);
    iParsedForms=(String[])parsedList.toArray(new String[parsedList.size()]);
  }
  iBefore=before;
  iUseBefore=useBefore;
  iUseAfter=useAfter;
}
Program: 13963
Project: 13963
Buggy source:
public DateTimeField getField(Chronology chrono){
  DateTimeField wrappedField=iWrappedType.getField(chrono);
  RemainderDateTimeField field=iRecent;
  if (field.getWrappedField() == wrappedField) {
    return field;
  }
  field=new RemainderDateTimeField(wrappedField,iType,iDivisor);
  iRecent=field;
  return field;
}

Fixed version (ground truth):
public DateTimeField getField(Chronology chrono){
  DateTimeField wrappedField=iWrappedType.getField(chrono);
  RemainderDateTimeField field=iRecent;
  if (field != null && field.getWrappedField() == wrappedField) {
    return field;
  }
  field=new RemainderDateTimeField(wrappedField,iType,iDivisor);
  iRecent=field;
  return field;
}
Program: 13964
Project: 13964
Buggy source:
/** 
 * This method assumes that this field is properly rounded on 1970-01-01T00:00:00. If the rounding alignment differs, override this method as follows: <pre> return super.roundCeiling(instant + ALIGNMENT_MILLIS) - ALIGNMENT_MILLIS; </pre>
 */
public long roundCeiling(long instant){
  if (instant >= 0) {
    instant-=1;
    return instant - instant % iUnitMillis + iUnitMillis;
  }
 else {
    return instant - instant % iUnitMillis;
  }
}

Fixed version (ground truth):
/** 
 * This method assumes that this field is properly rounded on 1970-01-01T00:00:00. If the rounding alignment differs, override this method as follows: <pre> return super.roundCeiling(instant + ALIGNMENT_MILLIS) - ALIGNMENT_MILLIS; </pre>
 */
public long roundCeiling(long instant){
  if (instant > 0) {
    instant-=1;
    return instant - instant % iUnitMillis + iUnitMillis;
  }
 else {
    return instant - instant % iUnitMillis;
  }
}
Program: 13965
Project: 13965
Buggy source:
long set(long millis){
  if (iText == null) {
    return iField.set(millis,iValue);
  }
 else {
    return iField.set(millis,iText,iLocale);
  }
}

Fixed version (ground truth):
long set(long millis,boolean reset){
  if (iText == null) {
    millis=iField.set(millis,iValue);
  }
 else {
    millis=iField.set(millis,iText,iLocale);
  }
  if (reset) {
    millis=iField.roundFloor(millis);
  }
  return millis;
}
Program: 13966
Project: 13966
Buggy source:
/** 
 * Computes the parsed datetime by setting the saved fields. This method is idempotent, but it is not thread-safe.
 * @return milliseconds since 1970-01-01T00:00:00Z
 * @throws IllegalArgumentException if any field is out of range
 */
public long computeMillis(){
  SavedField[] savedFields=iSavedFields;
  int count=iSavedFieldsCount;
  if (iSavedFieldsShared) {
    iSavedFields=savedFields=(SavedField[])iSavedFields.clone();
    iSavedFieldsShared=false;
  }
  sort(savedFields,count);
  long millis=iMillis;
  for (int i=0; i < count; i++) {
    millis=savedFields[i].set(millis);
  }
  if (iZone == null) {
    millis-=iOffset;
  }
 else {
    int offset=iZone.getOffsetFromLocal(millis);
    millis-=offset;
    if (offset != iZone.getOffset(millis)) {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  return millis;
}

Fixed version (ground truth):
/** 
 * Computes the parsed datetime by setting the saved fields. This method is idempotent, but it is not thread-safe.
 * @param resetFields false by default, but when true, unsaved field values are cleared
 * @return milliseconds since 1970-01-01T00:00:00Z
 * @throws IllegalArgumentException if any field is out of range
 */
public long computeMillis(boolean resetFields){
  SavedField[] savedFields=iSavedFields;
  int count=iSavedFieldsCount;
  if (iSavedFieldsShared) {
    iSavedFields=savedFields=(SavedField[])iSavedFields.clone();
    iSavedFieldsShared=false;
  }
  sort(savedFields,count);
  long millis=iMillis;
  for (int i=0; i < count; i++) {
    millis=savedFields[i].set(millis,resetFields);
  }
  if (iZone == null) {
    millis-=iOffset;
  }
 else {
    int offset=iZone.getOffsetFromLocal(millis);
    millis-=offset;
    if (offset != iZone.getOffset(millis)) {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
  return millis;
}
Program: 13967
Project: 13967
Buggy source:
/** 
 * Adds this period to the given instant using the chronology of the specified instant (if present), returning a new Instant. <p> To add just once, pass in a scalar of one. To subtract once, pass in a scalar of minus one.
 * @param instant  the instant to add the period to, null means now
 * @param scalar  the number of times to add the period, negative to subtract
 * @return instant with the original value plus this period times scalar
 * @throws ArithmeticException if the result of the calculation is too large
 */
public final Instant addTo(ReadableInstant instant,int scalar){
  long instantMillis=DateTimeUtils.getInstantMillis(instant);
  return new Instant(addTo(instantMillis,scalar,instant.getChronology()));
}

Fixed version (ground truth):
/** 
 * Adds this period to the given instant using the chronology of the specified instant (if present), returning a new Instant. <p> To add just once, pass in a scalar of one. To subtract once, pass in a scalar of minus one.
 * @param instant  the instant to add the period to, null means now
 * @param scalar  the number of times to add the period, negative to subtract
 * @return instant with the original value plus this period times scalar
 * @throws ArithmeticException if the result of the calculation is too large
 */
public final Instant addTo(ReadableInstant instant,int scalar){
  long instantMillis=DateTimeUtils.getInstantMillis(instant);
  Chronology chrono=DateTimeUtils.getInstantChronology(instant,null);
  return new Instant(addTo(instantMillis,scalar,chrono));
}
Program: 13968
Project: 13968
Buggy source:
/** 
 * Sets the duration of this time interval, preserving the end instant.
 * @param duration  new duration for interval, null means zero length
 * @throws IllegalArgumentException if the end is before the start
 * @throws ArithmeticException if the start instant exceeds the capacity of a long
 */
public void setDurationBeforeEnd(ReadableDuration duration){
  long durationMillis=DateTimeUtils.getDurationMillis(duration);
  setStartMillis(FieldUtils.safeAdd(getStartMillis(),-durationMillis));
}

Fixed version (ground truth):
/** 
 * Sets the duration of this time interval, preserving the end instant.
 * @param duration  new duration for interval, null means zero length
 * @throws IllegalArgumentException if the end is before the start
 * @throws ArithmeticException if the start instant exceeds the capacity of a long
 */
public void setDurationBeforeEnd(ReadableDuration duration){
  long durationMillis=DateTimeUtils.getDurationMillis(duration);
  setStartMillis(FieldUtils.safeAdd(getEndMillis(),-durationMillis));
}
Program: 13969
Project: 13969
Buggy source:
public void testAddIntoRWI3(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,1);
  expected=ISOChronology.getInstance().months().add(expected,2);
  expected=ISOChronology.getInstance().weeks().add(expected,3);
  expected=ISOChronology.getInstance().days().add(expected,4);
  expected=ISOChronology.getInstance().hours().add(expected,5);
  expected=ISOChronology.getInstance().minutes().add(expected,6);
  expected=ISOChronology.getInstance().seconds().add(expected,7);
  expected=ISOChronology.getInstance().millis().add(expected,8);
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  try {
    test.addInto(null,1);
    fail();
  }
 catch (  IllegalArgumentException ex) {
  }
}

Fixed version (ground truth):
public void testAddIntoRWI3(){
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  try {
    test.addInto(null,1);
    fail();
  }
 catch (  IllegalArgumentException ex) {
  }
}
Program: 13970
Project: 13970
Buggy source:
public void testAddTo2(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,-2);
  expected=ISOChronology.getInstance().months().add(expected,-4);
  expected=ISOChronology.getInstance().weeks().add(expected,-6);
  expected=ISOChronology.getInstance().days().add(expected,-8);
  expected=ISOChronology.getInstance().hours().add(expected,-10);
  expected=ISOChronology.getInstance().minutes().add(expected,-12);
  expected=ISOChronology.getInstance().seconds().add(expected,-14);
  expected=ISOChronology.getInstance().millis().add(expected,-16);
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  long added=test.addTo(TEST_TIME_NOW,-2);
  assertEquals(expected,added);
}

Fixed version (ground truth):
public void testAddTo2(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstanceUTC().years().add(expected,-2);
  expected=ISOChronology.getInstanceUTC().months().add(expected,-4);
  expected=ISOChronology.getInstanceUTC().weeks().add(expected,-6);
  expected=ISOChronology.getInstanceUTC().days().add(expected,-8);
  expected=ISOChronology.getInstanceUTC().hours().add(expected,-10);
  expected=ISOChronology.getInstanceUTC().minutes().add(expected,-12);
  expected=ISOChronology.getInstanceUTC().seconds().add(expected,-14);
  expected=ISOChronology.getInstanceUTC().millis().add(expected,-16);
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  long added=test.addTo(TEST_TIME_NOW,-2);
  assertEquals(expected,added);
}
Program: 13971
Project: 13971
Buggy source:
public void testAddTo1(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,1);
  expected=ISOChronology.getInstance().months().add(expected,2);
  expected=ISOChronology.getInstance().weeks().add(expected,3);
  expected=ISOChronology.getInstance().days().add(expected,4);
  expected=ISOChronology.getInstance().hours().add(expected,5);
  expected=ISOChronology.getInstance().minutes().add(expected,6);
  expected=ISOChronology.getInstance().seconds().add(expected,7);
  expected=ISOChronology.getInstance().millis().add(expected,8);
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  long added=test.addTo(TEST_TIME_NOW,1);
  assertEquals(expected,added);
}

Fixed version (ground truth):
public void testAddTo1(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstanceUTC().years().add(expected,1);
  expected=ISOChronology.getInstanceUTC().months().add(expected,2);
  expected=ISOChronology.getInstanceUTC().weeks().add(expected,3);
  expected=ISOChronology.getInstanceUTC().days().add(expected,4);
  expected=ISOChronology.getInstanceUTC().hours().add(expected,5);
  expected=ISOChronology.getInstanceUTC().minutes().add(expected,6);
  expected=ISOChronology.getInstanceUTC().seconds().add(expected,7);
  expected=ISOChronology.getInstanceUTC().millis().add(expected,8);
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  long added=test.addTo(TEST_TIME_NOW,1);
  assertEquals(expected,added);
}
Program: 13972
Project: 13972
Buggy source:
public void testAddToRI2(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,-2);
  expected=ISOChronology.getInstance().months().add(expected,-4);
  expected=ISOChronology.getInstance().weeks().add(expected,-6);
  expected=ISOChronology.getInstance().days().add(expected,-8);
  expected=ISOChronology.getInstance().hours().add(expected,-10);
  expected=ISOChronology.getInstance().minutes().add(expected,-12);
  expected=ISOChronology.getInstance().seconds().add(expected,-14);
  expected=ISOChronology.getInstance().millis().add(expected,-16);
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(new Instant(),-2);
  assertEquals(expected,added.getMillis());
}

Fixed version (ground truth):
public void testAddToRI2(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstanceUTC().years().add(expected,-2);
  expected=ISOChronology.getInstanceUTC().months().add(expected,-4);
  expected=ISOChronology.getInstanceUTC().weeks().add(expected,-6);
  expected=ISOChronology.getInstanceUTC().days().add(expected,-8);
  expected=ISOChronology.getInstanceUTC().hours().add(expected,-10);
  expected=ISOChronology.getInstanceUTC().minutes().add(expected,-12);
  expected=ISOChronology.getInstanceUTC().seconds().add(expected,-14);
  expected=ISOChronology.getInstanceUTC().millis().add(expected,-16);
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(new Instant(),-2);
  assertEquals(expected,added.getMillis());
}
Program: 13973
Project: 13973
Buggy source:
public void testAddToRI1(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,1);
  expected=ISOChronology.getInstance().months().add(expected,2);
  expected=ISOChronology.getInstance().weeks().add(expected,3);
  expected=ISOChronology.getInstance().days().add(expected,4);
  expected=ISOChronology.getInstance().hours().add(expected,5);
  expected=ISOChronology.getInstance().minutes().add(expected,6);
  expected=ISOChronology.getInstance().seconds().add(expected,7);
  expected=ISOChronology.getInstance().millis().add(expected,8);
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(new Instant(),1);
  assertEquals(expected,added.getMillis());
}

Fixed version (ground truth):
public void testAddToRI1(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstanceUTC().years().add(expected,1);
  expected=ISOChronology.getInstanceUTC().months().add(expected,2);
  expected=ISOChronology.getInstanceUTC().weeks().add(expected,3);
  expected=ISOChronology.getInstanceUTC().days().add(expected,4);
  expected=ISOChronology.getInstanceUTC().hours().add(expected,5);
  expected=ISOChronology.getInstanceUTC().minutes().add(expected,6);
  expected=ISOChronology.getInstanceUTC().seconds().add(expected,7);
  expected=ISOChronology.getInstanceUTC().millis().add(expected,8);
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(new Instant(),1);
  assertEquals(expected,added.getMillis());
}
Program: 13974
Project: 13974
Buggy source:
public void testAddToRI3(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,1);
  expected=ISOChronology.getInstance().months().add(expected,2);
  expected=ISOChronology.getInstance().weeks().add(expected,3);
  expected=ISOChronology.getInstance().days().add(expected,4);
  expected=ISOChronology.getInstance().hours().add(expected,5);
  expected=ISOChronology.getInstance().minutes().add(expected,6);
  expected=ISOChronology.getInstance().seconds().add(expected,7);
  expected=ISOChronology.getInstance().millis().add(expected,8);
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(null,1);
  assertEquals(expected,added.getMillis());
}

Fixed version (ground truth):
public void testAddToRI3(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,-2);
  expected=ISOChronology.getInstance().months().add(expected,-4);
  expected=ISOChronology.getInstance().weeks().add(expected,-6);
  expected=ISOChronology.getInstance().days().add(expected,-8);
  expected=ISOChronology.getInstance().hours().add(expected,-10);
  expected=ISOChronology.getInstance().minutes().add(expected,-12);
  expected=ISOChronology.getInstance().seconds().add(expected,-14);
  expected=ISOChronology.getInstance().millis().add(expected,-16);
  Duration test=new Duration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(new DateTime(),-2);
  assertEquals(expected,added.getMillis());
}
Program: 13975
Project: 13975
Buggy source:
public void testAddToRI2(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,-2);
  expected=ISOChronology.getInstance().months().add(expected,-4);
  expected=ISOChronology.getInstance().weeks().add(expected,-6);
  expected=ISOChronology.getInstance().days().add(expected,-8);
  expected=ISOChronology.getInstance().hours().add(expected,-10);
  expected=ISOChronology.getInstance().minutes().add(expected,-12);
  expected=ISOChronology.getInstance().seconds().add(expected,-14);
  expected=ISOChronology.getInstance().millis().add(expected,-16);
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(new Instant(),-2);
  assertEquals(expected,added.getMillis());
}

Fixed version (ground truth):
public void testAddToRI2(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstanceUTC().years().add(expected,-2);
  expected=ISOChronology.getInstanceUTC().months().add(expected,-4);
  expected=ISOChronology.getInstanceUTC().weeks().add(expected,-6);
  expected=ISOChronology.getInstanceUTC().days().add(expected,-8);
  expected=ISOChronology.getInstanceUTC().hours().add(expected,-10);
  expected=ISOChronology.getInstanceUTC().minutes().add(expected,-12);
  expected=ISOChronology.getInstanceUTC().seconds().add(expected,-14);
  expected=ISOChronology.getInstanceUTC().millis().add(expected,-16);
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(new Instant(),-2);
  assertEquals(expected,added.getMillis());
}
Program: 13976
Project: 13976
Buggy source:
public void testAddToRI1(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,1);
  expected=ISOChronology.getInstance().months().add(expected,2);
  expected=ISOChronology.getInstance().weeks().add(expected,3);
  expected=ISOChronology.getInstance().days().add(expected,4);
  expected=ISOChronology.getInstance().hours().add(expected,5);
  expected=ISOChronology.getInstance().minutes().add(expected,6);
  expected=ISOChronology.getInstance().seconds().add(expected,7);
  expected=ISOChronology.getInstance().millis().add(expected,8);
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(new Instant(),1);
  assertEquals(expected,added.getMillis());
}

Fixed version (ground truth):
public void testAddToRI1(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstanceUTC().years().add(expected,1);
  expected=ISOChronology.getInstanceUTC().months().add(expected,2);
  expected=ISOChronology.getInstanceUTC().weeks().add(expected,3);
  expected=ISOChronology.getInstanceUTC().days().add(expected,4);
  expected=ISOChronology.getInstanceUTC().hours().add(expected,5);
  expected=ISOChronology.getInstanceUTC().minutes().add(expected,6);
  expected=ISOChronology.getInstanceUTC().seconds().add(expected,7);
  expected=ISOChronology.getInstanceUTC().millis().add(expected,8);
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(new Instant(),1);
  assertEquals(expected,added.getMillis());
}
Program: 13977
Project: 13977
Buggy source:
public void testAddToRI3(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,1);
  expected=ISOChronology.getInstance().months().add(expected,2);
  expected=ISOChronology.getInstance().weeks().add(expected,3);
  expected=ISOChronology.getInstance().days().add(expected,4);
  expected=ISOChronology.getInstance().hours().add(expected,5);
  expected=ISOChronology.getInstance().minutes().add(expected,6);
  expected=ISOChronology.getInstance().seconds().add(expected,7);
  expected=ISOChronology.getInstance().millis().add(expected,8);
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(null,1);
  assertEquals(expected,added.getMillis());
}

Fixed version (ground truth):
public void testAddToRI3(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,-2);
  expected=ISOChronology.getInstance().months().add(expected,-4);
  expected=ISOChronology.getInstance().weeks().add(expected,-6);
  expected=ISOChronology.getInstance().days().add(expected,-8);
  expected=ISOChronology.getInstance().hours().add(expected,-10);
  expected=ISOChronology.getInstance().minutes().add(expected,-12);
  expected=ISOChronology.getInstance().seconds().add(expected,-14);
  expected=ISOChronology.getInstance().millis().add(expected,-16);
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  Instant added=test.addTo(new DateTime(),-2);
  assertEquals(expected,added.getMillis());
}
Program: 13978
Project: 13978
Buggy source:
public void testAddIntoRWI3(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,1);
  expected=ISOChronology.getInstance().months().add(expected,2);
  expected=ISOChronology.getInstance().weeks().add(expected,3);
  expected=ISOChronology.getInstance().days().add(expected,4);
  expected=ISOChronology.getInstance().hours().add(expected,5);
  expected=ISOChronology.getInstance().minutes().add(expected,6);
  expected=ISOChronology.getInstance().seconds().add(expected,7);
  expected=ISOChronology.getInstance().millis().add(expected,8);
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  try {
    test.addInto(null,1);
    fail();
  }
 catch (  IllegalArgumentException ex) {
  }
}

Fixed version (ground truth):
public void testAddIntoRWI3(){
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  try {
    test.addInto(null,1);
    fail();
  }
 catch (  IllegalArgumentException ex) {
  }
}
Program: 13979
Project: 13979
Buggy source:
public void testAddTo2(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,-2);
  expected=ISOChronology.getInstance().months().add(expected,-4);
  expected=ISOChronology.getInstance().weeks().add(expected,-6);
  expected=ISOChronology.getInstance().days().add(expected,-8);
  expected=ISOChronology.getInstance().hours().add(expected,-10);
  expected=ISOChronology.getInstance().minutes().add(expected,-12);
  expected=ISOChronology.getInstance().seconds().add(expected,-14);
  expected=ISOChronology.getInstance().millis().add(expected,-16);
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  long added=test.addTo(TEST_TIME_NOW,-2);
  assertEquals(expected,added);
}

Fixed version (ground truth):
public void testAddTo2(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstanceUTC().years().add(expected,-2);
  expected=ISOChronology.getInstanceUTC().months().add(expected,-4);
  expected=ISOChronology.getInstanceUTC().weeks().add(expected,-6);
  expected=ISOChronology.getInstanceUTC().days().add(expected,-8);
  expected=ISOChronology.getInstanceUTC().hours().add(expected,-10);
  expected=ISOChronology.getInstanceUTC().minutes().add(expected,-12);
  expected=ISOChronology.getInstanceUTC().seconds().add(expected,-14);
  expected=ISOChronology.getInstanceUTC().millis().add(expected,-16);
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  long added=test.addTo(TEST_TIME_NOW,-2);
  assertEquals(expected,added);
}
Program: 13980
Project: 13980
Buggy source:
public void testAddTo1(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstance().years().add(expected,1);
  expected=ISOChronology.getInstance().months().add(expected,2);
  expected=ISOChronology.getInstance().weeks().add(expected,3);
  expected=ISOChronology.getInstance().days().add(expected,4);
  expected=ISOChronology.getInstance().hours().add(expected,5);
  expected=ISOChronology.getInstance().minutes().add(expected,6);
  expected=ISOChronology.getInstance().seconds().add(expected,7);
  expected=ISOChronology.getInstance().millis().add(expected,8);
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  long added=test.addTo(TEST_TIME_NOW,1);
  assertEquals(expected,added);
}

Fixed version (ground truth):
public void testAddTo1(){
  long expected=TEST_TIME_NOW;
  expected=ISOChronology.getInstanceUTC().years().add(expected,1);
  expected=ISOChronology.getInstanceUTC().months().add(expected,2);
  expected=ISOChronology.getInstanceUTC().weeks().add(expected,3);
  expected=ISOChronology.getInstanceUTC().days().add(expected,4);
  expected=ISOChronology.getInstanceUTC().hours().add(expected,5);
  expected=ISOChronology.getInstanceUTC().minutes().add(expected,6);
  expected=ISOChronology.getInstanceUTC().seconds().add(expected,7);
  expected=ISOChronology.getInstanceUTC().millis().add(expected,8);
  MutableDuration test=new MutableDuration(1,2,3,4,5,6,7,8);
  long added=test.addTo(TEST_TIME_NOW,1);
  assertEquals(expected,added);
}
Program: 13981
Project: 13981
Buggy source:
/** 
 * Adds this duration into the given mutable instant. <p> To add just once, pass in a scalar of one. To subtract once, pass in a scalar of minus one.
 * @param instant  the instant to update with the added duration, must not be null
 * @param scalar  the number of times to add the duration, negative to subtract
 * @throws IllegalArgumentException if the instant is null
 * @throws ArithmeticException if the result of the calculation is too large
 */
public final void addInto(ReadWritableInstant instant,int scalar){
  if (instant == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  instant.setMillis(addTo(instant.getMillis(),scalar));
}

Fixed version (ground truth):
/** 
 * Adds this duration into the given mutable instant using the chronology of the specified mutable instant (if present). <p> To add just once, pass in a scalar of one. To subtract once, pass in a scalar of minus one.
 * @param instant  the instant to update with the added duration, must not be null
 * @param scalar  the number of times to add the duration, negative to subtract
 * @throws IllegalArgumentException if the instant is null
 * @throws ArithmeticException if the result of the calculation is too large
 */
public final void addInto(ReadWritableInstant instant,int scalar){
  if (instant == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  instant.setMillis(addTo(instant.getMillis(),scalar,instant.getChronology()));
}
Program: 13982
Project: 13982
Buggy source:
/** 
 * Adds this duration to the given instant, returning a new Instant. <p> To add just once, pass in a scalar of one. To subtract once, pass in a scalar of minus one.
 * @param instant  the instant to add the duration to, null means now
 * @param scalar  the number of times to add the duration, negative to subtract
 * @return instant with the original value plus this duration times scalar
 * @throws ArithmeticException if the result of the calculation is too large
 */
public final Instant addTo(ReadableInstant instant,int scalar){
  if (instant == null) {
    return new Instant(addTo(DateTimeUtils.currentTimeMillis(),scalar));
  }
  return new Instant(addTo(instant.getMillis(),scalar));
}

Fixed version (ground truth):
/** 
 * Adds this duration to the given instant using the chronology of the specified instant (if present), returning a new Instant. <p> To add just once, pass in a scalar of one. To subtract once, pass in a scalar of minus one.
 * @param instant  the instant to add the duration to, null means now
 * @param scalar  the number of times to add the duration, negative to subtract
 * @return instant with the original value plus this duration times scalar
 * @throws ArithmeticException if the result of the calculation is too large
 */
public final Instant addTo(ReadableInstant instant,int scalar){
  if (instant == null) {
    return new Instant(addTo(DateTimeUtils.currentTimeMillis(),scalar));
  }
  return new Instant(addTo(instant.getMillis(),scalar,instant.getChronology()));
}
Program: 13983
Project: 13983
Buggy source:
private static synchronized DateTimeFormatter offsetFormatter(){
  if (cOffsetFormatter == null) {
    cOffsetFormatter=new DateTimeFormatterBuilder(UTC).appendTimeZoneOffset(null,true,2,4).toFormatter();
  }
  return cOffsetFormatter;
}

Fixed version (ground truth):
private static synchronized DateTimeFormatter offsetFormatter(){
  if (cOffsetFormatter == null) {
    cOffsetFormatter=new DateTimeFormatterBuilder((Chronology)null,null).appendTimeZoneOffset(null,true,2,4).toFormatter();
  }
  return cOffsetFormatter;
}
Program: 13984
Project: 13984
Buggy source:
/** 
 * Creates a DateTimeFormatterBuilder with any chronology and locale.
 * @param chrono Chronology to use, or null for default of ISO
 * @param locale Locale to use, or null for default
 */
public DateTimeFormatterBuilder(Chronology chrono,Locale locale){
  if (chrono == null) {
    chrono=ISOChronology.getInstance();
  }
  if (locale == null) {
    locale=Locale.getDefault();
  }
  iChrono=chrono;
  iChronoUTC=chrono.withUTC();
  DateTimeZone zone=chrono.getZone();
  iLocale=locale;
  iElementPairs=new ArrayList();
}

Fixed version (ground truth):
/** 
 * Creates a DateTimeFormatterBuilder with any chronology and locale.
 * @param chrono Chronology to use, or null for default of ISO
 * @param locale Locale to use, or null for default
 */
public DateTimeFormatterBuilder(Chronology chrono,Locale locale){
  if (chrono == null) {
    if (DateTimeZone.getDefault() == null) {
      iChrono=iChronoUTC=null;
    }
 else {
      iChrono=iChronoUTC=ISOChronology.getInstance();
    }
  }
 else {
    iChrono=chrono;
    iChronoUTC=chrono.withUTC();
  }
  if (locale == null) {
    locale=Locale.getDefault();
  }
  iLocale=locale;
  iElementPairs=new ArrayList();
}
Program: 13986
Project: 13986
Buggy source:
/** 
 * Uses a shared duration field rather than creating a new one.
 * @param durationField shared duration field
 */
ImpreciseCutoverField(DateTimeField julianField,DateTimeField gregorianField,DurationField durationField){
  super(julianField,gregorianField);
  if (durationField == null) {
    durationField=new LinkedDurationField(iDurationField,this);
  }
  iDurationField=durationField;
}

Fixed version (ground truth):
/** 
 * Uses a shared duration field rather than creating a new one.
 * @param durationField shared duration field
 */
ImpreciseCutoverField(DateTimeField julianField,DateTimeField gregorianField,DurationField durationField,boolean convertByWeekyear){
  super(julianField,gregorianField,convertByWeekyear);
  if (durationField == null) {
    durationField=new LinkedDurationField(iDurationField,this);
  }
  iDurationField=durationField;
}
Program: 13987
Project: 13987
Buggy source:
CutoverField(DateTimeField julianField,DateTimeField gregorianField,long cutoverInstant){
  super(gregorianField.getName());
  iJulianField=julianField;
  iGregorianField=gregorianField;
  iCutover=cutoverInstant;
  iDurationField=gregorianField.getDurationField();
}

Fixed version (ground truth):
CutoverField(DateTimeField julianField,DateTimeField gregorianField,long cutoverInstant,boolean convertByWeekyear){
  super(gregorianField.getName());
  iJulianField=julianField;
  iGregorianField=gregorianField;
  iCutover=cutoverInstant;
  iConvertByWeekyear=convertByWeekyear;
  iDurationField=gregorianField.getDurationField();
}
Program: 13988
Project: 13988
Buggy source:
long julianToGregorian(long instant){
  return convert(instant,iJulianChronology,iGregorianChronology);
}

Fixed version (ground truth):
protected long julianToGregorian(long instant){
  if (iConvertByWeekyear) {
    return julianToGregorianByWeekyear(instant);
  }
 else {
    return julianToGregorianByYear(instant);
  }
}
Program: 13989
Project: 13989
Buggy source:
long gregorianToJulian(long instant){
  return convert(instant,iGregorianChronology,iJulianChronology);
}

Fixed version (ground truth):
protected long gregorianToJulian(long instant){
  if (iConvertByWeekyear) {
    return gregorianToJulianByWeekyear(instant);
  }
 else {
    return gregorianToJulianByYear(instant);
  }
}
Program: 13990
Project: 13990
Buggy source:
/** 
 * Called when applying a time zone.
 */
private GJChronology(Chronology base){
  super(base,null);
}

Fixed version (ground truth):
/** 
 * Called when applying a time zone.
 */
private GJChronology(Chronology base,JulianChronology julian,GregorianChronology gregorian,Instant cutoverInstant){
  super(base,new Object[]{julian,gregorian,cutoverInstant});
}
Program: 13991
Project: 13991
Buggy source:
/** 
 * Gets the cutover instant between Gregorian and Julian chronologies.
 * @return the cutover instant
 */
public Instant getGregorianCutover(){
  Instant cutover=iCutoverInstant;
  if (cutover == null) {
    iCutoverInstant=cutover=new Instant(iCutoverMillis);
  }
  return cutover;
}

Fixed version (ground truth):
/** 
 * Gets the cutover instant between Gregorian and Julian chronologies.
 * @return the cutover instant
 */
public Instant getGregorianCutover(){
  return iCutoverInstant;
}
Program: 13993
Project: 13993
Buggy source:
/** 
 * Constructs an instance from an Object that represents a date, using the specified chronology. <p> The recognised object types are defined in   {@link ConverterManager} andinclude ReadableInstant, String, Calendar and Date.
 * @param instant  the datetime object, must not be null
 * @param chronology  the chronology, null means ISOChronology
 * @throws IllegalArgumentException if the date or chronology is null
 */
protected AbstractPartialInstant(Object instant,final Chronology chronology){
  iChronology=selectChronologyUTC(chronology);
  InstantConverter converter=ConverterManager.getInstance().getInstantConverter(instant);
  iMillis=resetUnsupportedFields(toLocalTime(converter.getInstantMillis(instant),converter.getChronology(instant),iChronology));
}

Fixed version (ground truth):
/** 
 * Constructs an instance from an Object that represents a date, using the specified chronology. <p> The recognised object types are defined in   {@link ConverterManager} andinclude ReadableInstant, String, Calendar and Date.
 * @param instant  the datetime object, must not be null
 * @param chronology  the chronology, null means ISOChronology
 * @throws IllegalArgumentException if the date or chronology is null
 */
protected AbstractPartialInstant(Object instant,final Chronology chronology){
  InstantConverter converter=ConverterManager.getInstance().getInstantConverter(instant);
  Chronology original=converter.getChronology(instant,chronology);
  iChronology=selectChronologyUTC(original);
  iMillis=resetUnsupportedFields(toLocalTime(converter.getInstantMillis(instant,chronology),original,iChronology));
}
Program: 13994
Project: 13994
Buggy source:
/** 
 * Instructs the printer to emit a numeric weekyear field.
 * @param minDigits minumum number of digits to <i>print</i>
 * @param maxDigits maximum number of digits to <i>parse</i>, or the estimatedmaximum number of digits to print
 * @return this DateTimeFormatterBuilder
 */
public DateTimeFormatterBuilder appendWeekyear(final int minDigits,final int maxDigits){
  return appendDecimal(iChronoUTC.weekyear(),minDigits,maxDigits);
}

Fixed version (ground truth):
/** 
 * Instructs the printer to emit a numeric weekyear field.
 * @param minDigits minumum number of digits to <i>print</i>
 * @param maxDigits maximum number of digits to <i>parse</i>, or the estimatedmaximum number of digits to print
 * @return this DateTimeFormatterBuilder
 */
public DateTimeFormatterBuilder appendWeekyear(final int minDigits,final int maxDigits){
  return appendSignedDecimal(iChronoUTC.weekyear(),minDigits,maxDigits);
}
Program: 13995
Project: 13995
Buggy source:
public int parseInto(final DateTimeParserBucket bucket,final String text,final int position){
  DateTimeParser[] parsers=iParsers;
  int length=parsers.length;
  final Object originalState=bucket.saveState();
  boolean isOptional=false;
  int bestValidPos=position;
  Object bestValidState=null;
  int bestInvalidPos=position;
  for (int i=0; i < length; i++) {
    DateTimeParser parser=parsers[i];
    if (parser == null) {
      if (bestValidPos <= position) {
        return position;
      }
      isOptional=true;
      break;
    }
    int parsePos=parser.parseInto(bucket,text,position);
    if (parsePos >= position) {
      if (parsePos > bestValidPos) {
        if (parsePos >= text.length() || (i + 1) >= length || parsers[i + 1] == null) {
          return parsePos;
        }
        bestValidPos=parsePos;
        bestValidState=bucket.saveState();
      }
    }
 else {
      bucket.undoChanges(originalState);
      if (parsePos < 0) {
        parsePos=~parsePos;
        if (parsePos > bestInvalidPos) {
          bestInvalidPos=parsePos;
        }
      }
    }
  }
  if (bestValidPos > position || (bestValidPos == position && isOptional)) {
    if (bestValidState != null) {
      bucket.undoChanges(bestValidState);
    }
    return bestValidPos;
  }
  return ~bestInvalidPos;
}

Fixed version (ground truth):
public int parseInto(final DateTimeParserBucket bucket,final String text,final int position){
  DateTimeParser[] parsers=iParsers;
  int length=parsers.length;
  final Object originalState=bucket.saveState();
  boolean isOptional=false;
  int bestValidPos=position;
  Object bestValidState=null;
  int bestInvalidPos=position;
  for (int i=0; i < length; i++) {
    DateTimeParser parser=parsers[i];
    if (parser == null) {
      if (bestValidPos <= position) {
        return position;
      }
      isOptional=true;
      break;
    }
    int parsePos=parser.parseInto(bucket,text,position);
    if (parsePos >= position) {
      if (parsePos > bestValidPos) {
        if (parsePos >= text.length() || (i + 1) >= length || parsers[i + 1] == null) {
          return parsePos;
        }
        bestValidPos=parsePos;
        bestValidState=bucket.saveState();
      }
    }
 else {
      if (parsePos < 0) {
        parsePos=~parsePos;
        if (parsePos > bestInvalidPos) {
          bestInvalidPos=parsePos;
        }
      }
    }
    bucket.restoreState(originalState);
  }
  if (bestValidPos > position || (bestValidPos == position && isOptional)) {
    if (bestValidState != null) {
      bucket.restoreState(bestValidState);
    }
    return bestValidPos;
  }
  return ~bestInvalidPos;
}