nus-yam/ex-repair huggingface dataset:
Program: 52114
Project: 52114
Buggy source:
long getSecondaryAddress(StoreRecovery recovery,ExcerptContext ec,long timeoutMS,LongArrayValues index2indexArr,int index2) throws EOFException, UnrecoverableTimeoutException, StreamCorruptedException {
  try {
    return getSecondaryAddress1(recovery,ec,timeoutMS,index2indexArr,index2);
  }
 catch (  TimeoutException fallback) {
    ec.wire().pauser().reset();
    ec.wireForIndex().pauser().reset();
    return recovery.recoverSecondaryAddress(index2indexArr,index2,() -> getSecondaryAddress1(recovery,ec,timeoutMS,index2indexArr,index2),timeoutMS);
  }
}

Fixed version (ground truth):
private long getSecondaryAddress(StoreRecovery recovery,ExcerptContext ec,long timeoutMS,LongArrayValues index2indexArr,int index2) throws EOFException, UnrecoverableTimeoutException, StreamCorruptedException {
  try {
    return getSecondaryAddress1(recovery,ec,timeoutMS,index2indexArr,index2);
  }
 catch (  TimeoutException fallback) {
    ec.wire().pauser().reset();
    ec.wireForIndex().pauser().reset();
    return recovery.recoverSecondaryAddress(index2indexArr,index2,() -> getSecondaryAddress1(recovery,ec,timeoutMS,index2indexArr,index2),timeoutMS);
  }
}
Program: 52115
Project: 52115
Buggy source:
long sequenceForPosition(@NotNull StoreRecovery recovery,@NotNull ExcerptContext ec,final long position,boolean inclusive) throws EOFException, StreamCorruptedException {
}

Fixed version (ground truth):
long sequenceForPosition(@NotNull StoreRecovery recovery,@NotNull ExcerptContext ec,final long position,boolean inclusive) throws StreamCorruptedException {
}
Program: 52116
Project: 52116
Buggy source:
@NotNull private LongArrayValues arrayForAddress(@NotNull Wire wire,long secondaryAddress){
  LongArrayValuesHolder holder=getIndexArray();
  if (holder.address == secondaryAddress)   return holder.values;
  holder.address=secondaryAddress;
  wire.bytes().readPositionRemaining(secondaryAddress,256 << 20);
  wire.readMetaDataHeader();
  return array(wire,holder.values,false);
}

Fixed version (ground truth):
@NotNull private LongArrayValues arrayForAddress(@NotNull Wire wire,long secondaryAddress){
  LongArrayValuesHolder holder=getIndexArray();
  if (holder.address == secondaryAddress)   return holder.values;
  holder.address=secondaryAddress;
  wire.bytes().readPositionRemaining(secondaryAddress,4);
  wire.readMetaDataHeader();
  return array(wire,holder.values,false);
}
Program: 52117
Project: 52117
Buggy source:
@Override public boolean moveToIndex(final long index){
  if (index() == index)   return true;
  final ScanResult scanResult=moveToIndexResult(index);
  return scanResult == FOUND;
}

Fixed version (ground truth):
@Override public boolean moveToIndex(final long index){
  final ScanResult scanResult=moveToIndexResult(index);
  if (scanResult == NOT_FOUND) {
    try {
      long last=approximateLastIndex();
      if (index == last) {
        state=FOUND_CYCLE;
        return true;
      }
    }
 catch (    EOFException e) {
      return false;
    }
  }
  return scanResult == FOUND;
}
Program: 52118
Project: 52118
Buggy source:
@Ignore @Test public void testTailer() throws Exception {
  final Path dir=Files.createTempDirectory("String_Node_Str");
  final SingleChronicleQueueBuilder builder=ChronicleQueueBuilder.single(dir.toString()).rollCycle(RollCycles.TEST_SECONDLY);
  final RollingChronicleQueue queue=builder.build();
  queue.acquireAppender().writeText("String_Node_Str");
  ExcerptTailer excerptTailer=queue.createTailer().toEnd();
  long index=excerptTailer.index();
  System.out.println("String_Node_Str" + Long.toHexString(index));
  Assert.assertTrue(excerptTailer.moveToIndex(index));
}

Fixed version (ground truth):
@Test public void testTailer() throws Exception {
  final Path dir=Files.createTempDirectory("String_Node_Str");
  final SingleChronicleQueueBuilder builder=ChronicleQueueBuilder.single(dir.toString()).rollCycle(RollCycles.TEST_SECONDLY);
  final RollingChronicleQueue queue=builder.build();
  queue.acquireAppender().writeText("String_Node_Str");
  ExcerptTailer tailer=queue.createTailer();
  ExcerptTailer excerptTailer=tailer.toEnd();
  long index=excerptTailer.index();
  System.out.println("String_Node_Str" + Long.toHexString(index));
  Assert.assertTrue(excerptTailer.moveToIndex(index));
}
Program: 52119
Project: 52119
Buggy source:
@Test public void testAppendedSkipToEndMultiThreaded() throws TimeoutException, ExecutionException, InterruptedException {
}

Fixed version (ground truth):
@Ignore("String_Node_Str") @Test public void testAppendedSkipToEndMultiThreaded() throws TimeoutException, ExecutionException, InterruptedException {
}
Program: 52120
Project: 52120
Buggy source:
private boolean next(boolean includeMetaData) throws UnrecoverableTimeoutException, StreamCorruptedException {
  for (int i=0; i < 1000; i++) {
switch (state) {
case UNINTIALISED:
      final long firstIndex=queue.firstIndex();
    if (firstIndex == Long.MAX_VALUE)     return false;
  if (!moveToIndex(firstIndex))   return false;
break;
case FOUND_CYCLE:
try {
return inAnCycle(includeMetaData);
}
 catch (EOFException eof) {
state=TailerState.END_OF_CYCLE;
}
break;
case END_OF_CYCLE:
Boolean x=atTheEndOfACycle();
if (x != null) return x;
break;
case BEHOND_START:
if (direction == FORWARD) {
state=UNINTIALISED;
continue;
}
return false;
case CYCLE_NOT_FOUND:
return moveToIndex(index);
default :
throw new AssertionError("String_Node_Str" + state);
}
}
throw new IllegalStateException("String_Node_Str");
}

Fixed version (ground truth):
private boolean next(boolean includeMetaData) throws UnrecoverableTimeoutException, StreamCorruptedException {
  for (int i=0; i < 1000; i++) {
switch (state) {
case UNINTIALISED:
      final long firstIndex=queue.firstIndex();
    if (firstIndex == Long.MAX_VALUE)     return false;
  if (!moveToIndex(firstIndex))   return false;
break;
case FOUND_CYCLE:
try {
boolean result=inAnCycle(includeMetaData);
if (!result) {
  state=TailerState.END_OF_CYCLE;
  break;
}
return result;
}
 catch (EOFException eof) {
state=TailerState.END_OF_CYCLE;
}
break;
case END_OF_CYCLE:
Boolean x=atTheEndOfACycle();
if (x != null) return x;
break;
case BEHOND_START_OF_CYCLE:
if (direction == FORWARD) {
state=UNINTIALISED;
continue;
}
if (direction == BACKWARD) {
state=END_OF_CYCLE;
continue;
}
throw new AssertionError("String_Node_Str" + direction);
case CYCLE_NOT_FOUND:
return moveToIndex(index);
default :
throw new AssertionError("String_Node_Str" + state);
}
}
throw new IllegalStateException("String_Node_Str");
}
Program: 52121
Project: 52121
Buggy source:
private boolean cycle(final int cycle,boolean createIfAbsent){
  if (this.cycle == cycle && state == FOUND_CYCLE) {
    return true;
  }
  if (this.store != null) {
    this.queue.release(this.store);
  }
  this.store=this.queue.storeForCycle(cycle,queue.epoch(),createIfAbsent);
  if (store == null) {
    context.wire(null);
    if (direction == BACKWARD)     state=BEHOND_START;
 else     state=CYCLE_NOT_FOUND;
    return false;
  }
  this.state=FOUND_CYCLE;
  this.cycle=cycle;
  resetWires();
  final Wire wire=wire();
  wire.parent(this);
  wire.pauser(queue.pauserSupplier.get());
  return true;
}

Fixed version (ground truth):
private boolean cycle(final int cycle,boolean createIfAbsent){
  if (this.cycle == cycle && state == FOUND_CYCLE) {
    return true;
  }
  if (this.store != null) {
    this.queue.release(this.store);
  }
  this.store=this.queue.storeForCycle(cycle,queue.epoch(),createIfAbsent);
  if (store == null) {
    context.wire(null);
    if (direction == BACKWARD)     state=BEHOND_START_OF_CYCLE;
 else     state=CYCLE_NOT_FOUND;
    return false;
  }
  this.state=FOUND_CYCLE;
  this.cycle=cycle;
  resetWires();
  final Wire wire=wire();
  wire.parent(this);
  wire.pauser(queue.pauserSupplier.get());
  return true;
}
Program: 52122
Project: 52122
Buggy source:
@Test public void testReadingWritingWhenCycleIsSkipped() throws Exception {
  final Path dir=Files.createTempDirectory("String_Node_Str");
  final RollCycles rollCycle=RollCycles.TEST_SECONDLY;
  try (ChronicleQueue queue=ChronicleQueueBuilder.single(dir.toString()).rollCycle(rollCycle).build()){
    queue.acquireAppender().writeText("String_Node_Str");
  }
   Thread.sleep(1100);
  try (ChronicleQueue queue=ChronicleQueueBuilder.single(dir.toString()).rollCycle(rollCycle).build()){
    queue.acquireAppender().writeText("String_Node_Str");
  }
   try (ChronicleQueue queue=ChronicleQueueBuilder.single(dir.toString()).rollCycle(rollCycle).build()){
    ExcerptTailer tailer=queue.createTailer();
    Assert.assertEquals("String_Node_Str",tailer.readText());
    Assert.assertEquals("String_Node_Str",tailer.readText());
  }
 }

Fixed version (ground truth):
@Test public void testReadingWritingWhenCycleIsSkipped() throws Exception {
  final Path dir=Files.createTempDirectory("String_Node_Str");
  final RollCycles rollCycle=RollCycles.TEST_SECONDLY;
  try (ChronicleQueue queue=ChronicleQueueBuilder.single(dir.toString()).rollCycle(rollCycle).build()){
    queue.acquireAppender().writeText("String_Node_Str");
  }
   Thread.sleep(2100);
  try (ChronicleQueue queue=ChronicleQueueBuilder.single(dir.toString()).rollCycle(rollCycle).build()){
    queue.acquireAppender().writeText("String_Node_Str");
  }
   try (ChronicleQueue queue=ChronicleQueueBuilder.single(dir.toString()).rollCycle(rollCycle).build()){
    ExcerptTailer tailer=queue.createTailer();
    Assert.assertEquals("String_Node_Str",tailer.readText());
    Assert.assertEquals("String_Node_Str",tailer.readText());
  }
 }
Program: 52123
Project: 52123
Buggy source:
public Long toLong(File file){
  return Instant.from(formatter.parse(fileToName.apply(file))).toEpochMilli() / length;
}

Fixed version (ground truth):
public Long toLong(File file){
}
Program: 52124
Project: 52124
Buggy source:
@Override public int nextCycle(int currentCycle,TailerDirection direction) throws ParseException {
  if (direction == NONE)   throw new AssertionError("String_Node_Str");
  final NavigableMap<Long,File> tree=cycleTree();
  final File currentCycleFile=dateCache.resourceFor(currentCycle).path;
  if (!currentCycleFile.exists())   throw new IllegalStateException("String_Node_Str" + "String_Node_Str" + currentCycleFile);
  Long key=dateCache.toLong(currentCycleFile);
  File file=tree.get(key);
  if (file == null)   throw new AssertionError("String_Node_Str" + currentCycleFile);
switch (direction) {
case FORWARD:
    return toCycle(tree.higherEntry(key));
case BACKWARD:
  return toCycle(tree.lowerEntry(key));
default :
throw new UnsupportedOperationException("String_Node_Str");
}
}

Fixed version (ground truth):
@Override public int nextCycle(int currentCycle,TailerDirection direction) throws ParseException {
}
Program: 52125
Project: 52125
Buggy source:
private boolean next(boolean includeMetaData) throws UnrecoverableTimeoutException, StreamCorruptedException {
  for (int i=0; i < 1000; i++) {
switch (state) {
case UNINTIALISED:
      final long firstIndex=queue.firstIndex();
    if (firstIndex == Long.MAX_VALUE)     return false;
  if (!moveToIndex(firstIndex))   return false;
break;
case FOUND_CYCLE:
try {
return inAnCycle(includeMetaData);
}
 catch (EOFException eof) {
state=TailerState.END_OF_CYCLE;
}
break;
case END_OF_CYCLE:
Boolean x=atTheEndOfACycle();
if (x != null) return x;
break;
default :
throw new AssertionError("String_Node_Str" + state);
}
}
throw new IllegalStateException("String_Node_Str");
}

Fixed version (ground truth):
private boolean next(boolean includeMetaData) throws UnrecoverableTimeoutException, StreamCorruptedException {
  for (int i=0; i < 1000; i++) {
switch (state) {
case UNINTIALISED:
      final long firstIndex=queue.firstIndex();
    if (firstIndex == Long.MAX_VALUE)     return false;
  if (!moveToIndex(firstIndex))   return false;
break;
case FOUND_CYCLE:
try {
return inAnCycle(includeMetaData);
}
 catch (EOFException eof) {
state=TailerState.END_OF_CYCLE;
}
break;
case END_OF_CYCLE:
Boolean x=atTheEndOfACycle();
if (x != null) return x;
break;
case BEHOND_START:
if (direction == FORWARD) {
state=UNINTIALISED;
continue;
}
return false;
default :
throw new AssertionError("String_Node_Str" + state);
}
}
throw new IllegalStateException("String_Node_Str");
}
Program: 52126
Project: 52126
Buggy source:
private boolean cycle(final int cycle,boolean createIfAbsent){
  if (this.cycle != cycle) {
    if (this.store != null) {
      this.queue.release(this.store);
    }
    this.store=this.queue.storeForCycle(cycle,queue.epoch(),createIfAbsent);
    if (store == null) {
      context.wire(null);
      return false;
    }
    this.cycle=cycle;
    resetWires();
    final Wire wire=wire();
    wire.parent(this);
    wire.pauser(queue.pauserSupplier.get());
  }
  return true;
}

Fixed version (ground truth):
private boolean cycle(final int cycle,boolean createIfAbsent){
  if (this.cycle != cycle) {
    if (this.store != null) {
      this.queue.release(this.store);
    }
    this.store=this.queue.storeForCycle(cycle,queue.epoch(),createIfAbsent);
    if (store == null) {
      context.wire(null);
      if (direction == BACKWARD)       state=TailerState.BEHOND_START;
      return false;
    }
    this.state=TailerState.FOUND_CYCLE;
    this.cycle=cycle;
    resetWires();
    final Wire wire=wire();
    wire.parent(this);
    wire.pauser(queue.pauserSupplier.get());
  }
  return true;
}
Program: 52127
Project: 52127
Buggy source:
@NotNull @Override public ExcerptTailer toEnd(){
  long index=approximateLastIndex();
  if (direction != TailerDirection.FORWARD)   index--;
  if (index != Long.MIN_VALUE)   moveToIndex(index);
  return this;
}

Fixed version (ground truth):
@NotNull @Override public ExcerptTailer toEnd(){
  long index=approximateLastIndex();
  if (direction != TailerDirection.FORWARD)   index--;
  if (index != Long.MIN_VALUE)   moveToIndex(index);
  if (state() == TailerState.CYCLE_NOT_FOUND)   state=UNINTIALISED;
  return this;
}
Program: 52128
Project: 52128
Buggy source:
@Test public void toEndTest(){
  String baseDir=OS.TARGET + "String_Node_Str" + System.nanoTime();
  System.out.println(baseDir);
  IOTools.shallowDeleteDirWithFiles(baseDir);
  List<Integer> results=new ArrayList<>();
  RollingChronicleQueue queue=SingleChronicleQueueBuilder.binary(baseDir).indexCount(8).indexSpacing(1).build();
  checkOneFile(baseDir);
  ExcerptAppender appender=queue.acquireAppender();
  checkOneFile(baseDir);
  for (int i=0; i < 10; i++) {
    final int j=i;
    appender.writeDocument(wire -> wire.write(() -> "String_Node_Str").int32(j));
  }
  checkOneFile(baseDir);
  ExcerptTailer tailer=queue.createTailer();
  checkOneFile(baseDir);
  tailer.toEnd();
  assertEquals(10,queue.rollCycle().toSequenceNumber(tailer.index()));
  checkOneFile(baseDir);
  fillResults(tailer,results);
  checkOneFile(baseDir);
  assertEquals(0,results.size());
  tailer.toStart();
  checkOneFile(baseDir);
  fillResults(tailer,results);
  assertEquals(10,results.size());
  checkOneFile(baseDir);
  try {
    IOTools.shallowDeleteDirWithFiles(baseDir);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
@Test public void toEndTest(){
  String baseDir=OS.TARGET + "String_Node_Str" + System.nanoTime();
  System.out.println(baseDir);
  IOTools.shallowDeleteDirWithFiles(baseDir);
  List<Integer> results=new ArrayList<>();
  RollingChronicleQueue queue=SingleChronicleQueueBuilder.binary(baseDir).indexCount(8).indexSpacing(1).build();
  checkOneFile(baseDir);
  ExcerptAppender appender=queue.acquireAppender();
  checkOneFile(baseDir);
  for (int i=0; i < 10; i++) {
    final int j=i;
    appender.writeDocument(wire -> wire.write(() -> "String_Node_Str").int32(j));
  }
  checkOneFile(baseDir);
  ExcerptTailer tailer=queue.createTailer();
  checkOneFile(baseDir);
  ExcerptTailer atEnd=tailer.toEnd();
  assertEquals(10,queue.rollCycle().toSequenceNumber(atEnd.index()));
  checkOneFile(baseDir);
  fillResults(atEnd,results);
  checkOneFile(baseDir);
  assertEquals(0,results.size());
  tailer.toStart();
  checkOneFile(baseDir);
  fillResults(tailer,results);
  assertEquals(10,results.size());
  checkOneFile(baseDir);
  try {
    IOTools.shallowDeleteDirWithFiles(baseDir);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
Program: 52129
Project: 52129
Buggy source:
@NotNull private List<Integer> fillResults(ExcerptTailer tailer,List<Integer> results){
  for (int i=0; i < 10; i++) {
    if (!tailer.readDocument(wire -> results.add(wire.read(() -> "String_Node_Str").int32())))     break;
  }
  return results;
}

Fixed version (ground truth):
@NotNull private List<Integer> fillResults(ExcerptTailer tailer,List<Integer> results){
  for (int i=0; i < 10; i++) {
    try (DocumentContext documentContext=tailer.readingDocument()){
      if (!documentContext.isPresent())       break;
      results.add(documentContext.wire().read(() -> "String_Node_Str").int32());
    }
   }
  return results;
}
Program: 52130
Project: 52130
Buggy source:
private static void dumpFile(File file){
  if (file.getName().endsWith(SingleChronicleQueue.SUFFIX)) {
    try (MappedBytes bytes=MappedBytes.mappedBytes(file,4 << 20)){
      bytes.readLimit(bytes.realCapacity());
      System.out.println(Wires.fromSizePrefixedBlobs(bytes));
    }
 catch (    IOException ioe) {
      System.err.println("String_Node_Str" + file + "String_Node_Str"+ ioe);
    }
  }
}

Fixed version (ground truth):
private static void dumpFile(File file){
  if (file.getName().endsWith(SingleChronicleQueue.SUFFIX)) {
    try (MappedBytes bytes=MappedBytes.mappedBytes(file,4 << 20)){
      bytes.readLimit(bytes.realCapacity());
      out.println(Wires.fromSizePrefixedBlobs(bytes));
    }
 catch (    IOException ioe) {
      err.println("String_Node_Str" + file + "String_Node_Str"+ ioe);
    }
  }
}
Program: 52131
Project: 52131
Buggy source:
public static void dump(String path){
  File path2=new File(path);
  if (path2.isDirectory()) {
    File[] files=path2.listFiles();
    if (files == null)     System.err.println("String_Node_Str" + path);
    for (    File file : files)     dumpFile(file);
  }
 else {
    dumpFile(path2);
  }
}

Fixed version (ground truth):
public static void dump(String path){
  File path2=new File(path);
  if (path2.isDirectory()) {
    File[] files=path2.listFiles();
    if (files == null)     err.println("String_Node_Str" + path);
    for (    File file : files)     dumpFile(file);
  }
 else {
    dumpFile(path2);
  }
}
Program: 52132
Project: 52132
Buggy source:
private void resetPosition() throws UnrecoverableTimeoutException {
  try {
    if (store == null || wire == null)     return;
    final long position=store.writePosition();
    wire.bytes().writePosition(position);
    if (lazyIndexing)     return;
    final long headerNumber=store.sequenceForPosition(this,position);
    wire.headerNumber(queue.rollCycle().toIndex(cycle,headerNumber + 1) - 1);
    checkIndex(wire.headerNumber(),wire.bytes().writePosition());
  }
 catch (  BufferOverflowException|EOFException|StreamCorruptedException e) {
    throw new AssertionError(e);
  }
}

Fixed version (ground truth):
private void resetPosition() throws UnrecoverableTimeoutException {
}
Program: 52133
Project: 52133
Buggy source:
void writeIndexForPosition(long index,long position) throws UnrecoverableTimeoutException, StreamCorruptedException {
}

Fixed version (ground truth):
void writeIndexForPosition(long index,long position) throws UnrecoverableTimeoutException, StreamCorruptedException {
  if (!lazyIndexing) {
    long sequenceNumber=queue.rollCycle().toSequenceNumber(index);
    store.setPositionForSequenceNumber(this,sequenceNumber,position);
  }
}
Program: 52134
Project: 52134
Buggy source:
/** 
 * Moves the position to the index
 * @param ec      the data structure we are navigating
 * @param index     the index we wish to move to
 * @return whether the index was found for reading.
 */
@Override public ScanResult moveToIndexForRead(@NotNull ExcerptContext ec,long index){
  try {
    return indexing.moveToIndex(recovery,ec,index);
  }
 catch (  UnrecoverableTimeoutException|StreamCorruptedException e) {
    return ScanResult.NOT_REACHED;
  }
}

Fixed version (ground truth):
/** 
 * Moves the position to the index
 * @param ec    the data structure we are navigating
 * @param index the index we wish to move to
 * @return whether the index was found for reading.
 */
@Override public ScanResult moveToIndexForRead(@NotNull ExcerptContext ec,long index){
  try {
    return indexing.moveToIndex(recovery,ec,index);
  }
 catch (  UnrecoverableTimeoutException|StreamCorruptedException e) {
    return ScanResult.NOT_REACHED;
  }
}
Program: 52135
Project: 52135
Buggy source:
@Override public WireStore writePosition(long position){
  writePosition.setMaxValue(position);
  return this;
}

Fixed version (ground truth):
@Override public WireStore writePosition(long position){
  int header=mappedBytes.readVolatileInt(position);
  if (Wires.isReadyData(header))   writePosition.setMaxValue(position);
 else   throw new AssertionError();
  return this;
}
Program: 52136
Project: 52136
Buggy source:
@Test public void testWriteBytesWithIndex() throws Exception {
  String tmp=OS.TARGET + "String_Node_Str" + System.nanoTime();
  try (SingleChronicleQueue queue=ChronicleQueueBuilder.single(tmp).build()){
    ExcerptAppender appender=queue.acquireAppender();
    appender.writeBytes(0x421d00000000L,Bytes.from("String_Node_Str"));
    appender.writeBytes(0x421d00000001L,Bytes.from("String_Node_Str"));
  }
   try (SingleChronicleQueue queue=ChronicleQueueBuilder.single(tmp).build()){
    ExcerptAppender appender=queue.acquireAppender();
    try {
      appender.writeBytes(0x421d00000000L,Bytes.from("String_Node_Str"));
      fail();
    }
 catch (    IllegalStateException e) {
      assertEquals("String_Node_Str",e.getMessage());
    }
  }
   try (SingleChronicleQueue queue=ChronicleQueueBuilder.single(tmp).build()){
    ExcerptAppender appender=queue.acquireAppender();
    try {
      appender.writeBytes(0x421d00000003L,Bytes.from("String_Node_Str"));
      fail();
    }
 catch (    IllegalStateException e) {
      assertEquals("String_Node_Str",e.getMessage());
    }
  }
   try (SingleChronicleQueue queue=ChronicleQueueBuilder.single(tmp).build()){
    ExcerptAppender appender=queue.acquireAppender();
    appender.writeBytes(0x421d00000002L,Bytes.from("String_Node_Str"));
    appender.writeBytes(0x421d00000003L,Bytes.from("String_Node_Str"));
  }
   try {
    IOTools.deleteDirWithFiles(tmp,2);
  }
 catch (  IORuntimeException ignored) {
  }
}

Fixed version (ground truth):
@Test public void testWriteBytesWithIndex() throws Exception {
  String tmp=OS.TARGET + "String_Node_Str" + System.nanoTime();
  try (SingleChronicleQueue queue=ChronicleQueueBuilder.single(tmp).rollCycle(TEST_DAILY).build()){
    ExcerptAppender appender=queue.acquireAppender();
    appender.writeBytes(0x421d00000000L,Bytes.from("String_Node_Str"));
    appender.writeBytes(0x421d00000001L,Bytes.from("String_Node_Str"));
  }
   try (SingleChronicleQueue queue=ChronicleQueueBuilder.single(tmp).build()){
    ExcerptAppender appender=queue.acquireAppender();
    try {
      appender.writeBytes(0x421d00000000L,Bytes.from("String_Node_Str"));
      fail();
    }
 catch (    IllegalStateException e) {
      assertEquals("String_Node_Str",e.getMessage());
    }
  }
   try (SingleChronicleQueue queue=ChronicleQueueBuilder.single(tmp).build()){
    ExcerptAppender appender=queue.acquireAppender();
    try {
      appender.writeBytes(0x421d00000003L,Bytes.from("String_Node_Str"));
      fail();
    }
 catch (    IllegalStateException e) {
      assertEquals("String_Node_Str",e.getMessage());
    }
  }
   try (SingleChronicleQueue queue=ChronicleQueueBuilder.single(tmp).build()){
    ExcerptAppender appender=queue.acquireAppender();
    appender.writeBytes(0x421d00000002L,Bytes.from("String_Node_Str"));
    appender.writeBytes(0x421d00000003L,Bytes.from("String_Node_Str"));
  }
   try {
    IOTools.deleteDirWithFiles(tmp,2);
  }
 catch (  IORuntimeException ignored) {
  }
}
Program: 52137
Project: 52137
Buggy source:
@Ignore @Test public void testAppendedSkipToEndMultiThreaded() throws TimeoutException, ExecutionException, InterruptedException {
  for (; ; ) {
    try (ChronicleQueue q=SingleChronicleQueueBuilder.binary(getTmpDir()).wireType(this.wireType).build()){
      final ThreadLocal<ExcerptAppender> tl=ThreadLocal.withInitial(() -> q.acquireAppender());
      int size=100;
      IntStream.range(0,size).parallel().forEach(i -> writeTestDocument(tl));
      ExcerptTailer tailer=q.createTailer();
      for (int i=0; i < size; i++) {
        try (DocumentContext dc=tailer.readingDocument(false)){
          long index=dc.index();
          long actual=dc.wire().read(() -> "String_Node_Str").int64(index);
          Assert.assertEquals(index,actual);
        }
       }
      System.out.println("String_Node_Str");
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
  }
}

Fixed version (ground truth):
@Test public void testAppendedSkipToEndMultiThreaded() throws TimeoutException, ExecutionException, InterruptedException {
  for (int j=0; j < 50; j++) {
    try (ChronicleQueue q=SingleChronicleQueueBuilder.binary(getTmpDir()).wireType(this.wireType).build()){
      final ThreadLocal<ExcerptAppender> tl=ThreadLocal.withInitial(() -> q.acquireAppender());
      int size=100;
      IntStream.range(0,size).parallel().forEach(i -> writeTestDocument(tl));
      ExcerptTailer tailer=q.createTailer();
      for (int i=0; i < size; i++) {
        try (DocumentContext dc=tailer.readingDocument(false)){
          Assert.assertEquals(dc.index(),dc.wire().read(() -> "String_Node_Str").int64());
        }
       }
      System.out.println("String_Node_Str");
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
  }
}
Program: 52138
Project: 52138
Buggy source:
private void writeTestDocument(ThreadLocal<ExcerptAppender> tl){
  try (DocumentContext dc=tl.get().writingDocument()){
    long index=dc.index();
    dc.wire().write("String_Node_Str").int64(index);
    lastPosition.set(dc.wire().bytes().writePosition());
    lastIndex.set(dc.index());
  }
 }

Fixed version (ground truth):
private void writeTestDocument(ThreadLocal<ExcerptAppender> tl){
  try (DocumentContext dc=tl.get().writingDocument()){
    long index=dc.index();
    dc.wire().write("String_Node_Str").int64(index);
  }
 }
Program: 52139
Project: 52139
Buggy source:
@NotNull @Override public ExcerptTailer toEnd(){
  long index=approximateLastIndex();
  if (index == Long.MIN_VALUE)   return this;
  if (direction != TailerDirection.FORWARD && queue.rollCycle().toSequenceNumber(index) != 0) {
    index--;
  }
  if (moveToIndexResult(index) == ScanResult.NOT_REACHED) {
    if (moveToIndexResult(index - 1) == ScanResult.NOT_REACHED)     Jvm.debug().on(getClass(),"String_Node_Str" + Long.toHexString(index - 1) + "String_Node_Str");
  }
  return this;
}

Fixed version (ground truth):
@NotNull @Override public ExcerptTailer toEnd(){
  this.index=approximateLastIndex();
  return this;
}
Program: 52140
Project: 52140
Buggy source:
/** 
 * Moves the position to the   {@code index} <p> The indexes are stored in many excerpts, sothe index2index tells chronicle where ( in other words the address of where ) the root first level targetIndex is stored. The indexing works like a tree, but only 2 levels deep, the root of the tree is at index2index ( this first level targetIndex is 1MB in size and there is only one of them, it only holds the addresses of the second level indexes, there will be many second level indexes ( created on demand ), each is about 1MB in size  (this second level targetIndex only stores the position of every 64th excerpt), so from every 64th excerpt a linear scan occurs.
 * @param recovery
 * @param wire     the data structure we are navigating
 * @param index    the index we wish to move to
 * @return the position of the {@code targetIndex} or -1 if the index can not be found
 */
ScanResult moveToIndex(StoreRecovery recovery,@NotNull final Wire wire,final long index,long timeoutMS) throws UnrecoverableTimeoutException, StreamCorruptedException {
  try {
    ScanResult scanResult=moveToIndex0(recovery,wire,index,timeoutMS);
    if (scanResult != null)     return scanResult;
  }
 catch (  EOFException fallback) {
  }
  return moveToIndexFromTheStart(wire,index);
}

Fixed version (ground truth):
/** 
 * Moves the position to the   {@code index} <p> The indexes are stored in many excerpts, so theindex2index tells chronicle where ( in other words the address of where ) the root first level targetIndex is stored. The indexing works like a tree, but only 2 levels deep, the root of the tree is at index2index ( this first level targetIndex is 1MB in size and there is only one of them, it only holds the addresses of the second level indexes, there will be many second level indexes ( created on demand ), each is about 1MB in size  (this second level targetIndex only stores the position of every 64th excerpt), so from every 64th excerpt a linear scan occurs.
 * @param recovery
 * @param wire     the data structure we are navigating
 * @param index    the index we wish to move to
 * @return the position of the {@code targetIndex} or -1 if the index can not be found
 */
ScanResult moveToIndex(StoreRecovery recovery,@NotNull final Wire wire,final long index,long timeoutMS) throws UnrecoverableTimeoutException, StreamCorruptedException {
  try {
    ScanResult scanResult=moveToIndex0(recovery,wire,index,timeoutMS);
    if (scanResult != null)     return scanResult;
  }
 catch (  EOFException fallback) {
  }
  return moveToIndexFromTheStart(wire,index);
}
Program: 52141
Project: 52141
Buggy source:
long linearScanByPosition(@NotNull final Wire wire,final long toPosition,final long fromKnownIndex,final long knownAddress) throws EOFException {
  @NotNull final Bytes<?> bytes=wire.bytes();
  bytes.readLimit(writePosition.getValue()).readPosition(knownAddress);
  long i=fromKnownIndex;
  while (bytes.readPosition() < toPosition) {
    WireIn.HeaderType headerType=wire.readDataHeader(true);
    int header=bytes.readVolatileInt();
    bytes.readSkip(Wires.lengthOf(header));
switch (headerType) {
case NONE:
      if (toPosition == Long.MAX_VALUE)       return i < 0 ? i : i - 1;
    long pos=bytes.readPosition();
  if (toPosition == pos)   return i;
throw new EOFException();
case META_DATA:
break;
case DATA:
++i;
break;
}
}
if (bytes.readPosition() == toPosition) return i;
throw new IllegalArgumentException("String_Node_Str");
}

Fixed version (ground truth):
long linearScanByPosition(@NotNull final Wire wire,final long toPosition,final long fromKnownIndex,final long knownAddress) throws EOFException {
  @NotNull final Bytes<?> bytes=wire.bytes();
  bytes.readLimit(writePosition.getValue()).readPosition(knownAddress);
  long i=fromKnownIndex;
  while (bytes.readPosition() < toPosition) {
    WireIn.HeaderType headerType=wire.readDataHeader(true);
    int header=bytes.readVolatileInt();
    bytes.readSkip(Wires.lengthOf(header));
switch (headerType) {
case NONE:
      if (toPosition == Long.MAX_VALUE)       return i < 0 ? i : i - 1;
    long pos=bytes.readPosition();
  if (toPosition == pos)   return i;
throw new EOFException("String_Node_Str" + toPosition + "String_Node_Str"+ pos);
case META_DATA:
break;
case DATA:
++i;
break;
}
}
if (bytes.readPosition() == toPosition) return i;
throw new IllegalArgumentException("String_Node_Str");
}
Program: 52142
Project: 52142
Buggy source:
/** 
 * moves the context to the index of   {@code toIndex} by doing a linear scans form a {@code fromKnownIndex} at  {@code knownAddress} <p/> note meta data is skipped and does notcount to the indexes
 * @param wire           if successful, moves the context to an address relating to theindex  {@code toIndex }
 * @param toIndex        the index that we wish to move the context to
 * @param fromKnownIndex a know index ( used as a starting point )
 * @param knownAddress   a know address ( used as a starting point )
 * @see SCQIndexing#moveToIndex
 */
private ScanResult linearScan(@NotNull final Wire wire,final long toIndex,final long fromKnownIndex,final long knownAddress){
  @NotNull final Bytes<?> bytes=wire.bytes();
  long end=writePosition.getValue();
  bytes.readLimit(bytes.capacity()).readPosition(knownAddress);
  for (long i=fromKnownIndex; ; i++) {
    try {
      if (wire.readDataHeader()) {
        if (i == toIndex)         return ScanResult.FOUND;
        if (bytes.readPosition() > end)         return ScanResult.NOT_REACHED;
        bytes.readSkip(Wires.lengthOf(bytes.readInt()));
        continue;
      }
    }
 catch (    EOFException fallback) {
    }
    return i == toIndex ? ScanResult.NOT_FOUND : ScanResult.NOT_REACHED;
  }
}

Fixed version (ground truth):
/** 
 * moves the context to the index of   {@code toIndex} by doing a linear scans form a {@code fromKnownIndex} at  {@code knownAddress} <p/> note meta data is skipped and does not count tothe indexes
 * @param wire           if successful, moves the context to an address relating to the index{@code toIndex }
 * @param toIndex        the index that we wish to move the context to
 * @param fromKnownIndex a know index ( used as a starting point )
 * @param knownAddress   a know address ( used as a starting point )
 * @see SCQIndexing#moveToIndex
 */
private ScanResult linearScan(@NotNull final Wire wire,final long toIndex,final long fromKnownIndex,final long knownAddress){
  @NotNull final Bytes<?> bytes=wire.bytes();
  long end=writePosition.getValue();
  bytes.readLimit(bytes.capacity()).readPosition(knownAddress);
  for (long i=fromKnownIndex; ; i++) {
    try {
      if (wire.readDataHeader()) {
        if (i == toIndex)         return ScanResult.FOUND;
        if (bytes.readPosition() > end)         return ScanResult.NOT_REACHED;
        bytes.readSkip(Wires.lengthOf(bytes.readInt()));
        continue;
      }
    }
 catch (    EOFException fallback) {
    }
    return i == toIndex ? ScanResult.NOT_FOUND : ScanResult.NOT_REACHED;
  }
}
Program: 52144
Project: 52144
Buggy source:
@Override public long indexFromPosition(int cycle,WireStore store,long position){
  final Wire wire=wireType().apply(store.bytes());
  long sequenceNumber=0;
  try {
    sequenceNumber=store.sequenceForPosition(wire,position,0);
  }
 catch (  EOFException|StreamCorruptedException e) {
    throw new AssertionError(e);
  }
  return rollCycle.toIndex(cycle,sequenceNumber);
}

Fixed version (ground truth):
@Override public long indexFromPosition(int cycle,WireStore store,final long position){
  final Wire wire=wireType().apply(store.bytes());
  long sequenceNumber=0;
  try {
    sequenceNumber=store.sequenceForPosition(wire,position,0);
  }
 catch (  EOFException|StreamCorruptedException e) {
    throw new AssertionError(e);
  }
  return rollCycle.toIndex(cycle,sequenceNumber);
}
Program: 52145
Project: 52145
Buggy source:
private <T>void append2(int length,WireWriter<T> wireWriter,T writer) throws UnrecoverableTimeoutException, EOFException, StreamCorruptedException {
  setCycle(Math.max(queue.cycle(),cycle + 1),true);
  position=store.writeHeader(wire,length,queue.timeoutMS);
  wireWriter.write(writer,wire);
  wire.updateHeader(length,position,false);
}

Fixed version (ground truth):
private <T>void append2(int length,WireWriter<T> wireWriter,T writer) throws UnrecoverableTimeoutException, EOFException, StreamCorruptedException {
  setCycle(Math.max(queue.cycle(),cycle + 1),true);
  position(store.writeHeader(wire,length,queue.timeoutMS));
  wireWriter.write(writer,wire);
  wire.updateHeader(length,position,false);
}
Program: 52146
Project: 52146
Buggy source:
@Override public long sequenceForPosition(Wire wire,long position,long timeoutMS) throws EOFException, UnrecoverableTimeoutException, StreamCorruptedException {
  final Bytes<?> bytes=wire.bytes();
  long position0=bytes.readPosition();
  long remaining0=bytes.readRemaining();
  try {
    return indexing.sequenceForPosition(recovery,wire,position,timeoutMS);
  }
  finally {
    bytes.readPositionRemaining(position0,remaining0);
  }
}

Fixed version (ground truth):
@Override public long sequenceForPosition(Wire wire,final long position,long timeoutMS) throws EOFException, UnrecoverableTimeoutException, StreamCorruptedException {
  final Bytes<?> bytes=wire.bytes();
  long position0=bytes.readPosition();
  long remaining0=bytes.readRemaining();
  try {
    return indexing.sequenceForPosition(recovery,wire,position,timeoutMS);
  }
  finally {
    bytes.readPositionRemaining(position0,remaining0);
  }
}
Program: 52147
Project: 52147
Buggy source:
@Test @Ignore public void testAppendedSkipToEndMultiThreaded() throws TimeoutException, ExecutionException, InterruptedException {
  try (ChronicleQueue q=SingleChronicleQueueBuilder.binary(getTmpDir()).wireType(this.wireType).build()){
    final ThreadLocal<ExcerptAppender> tl=ThreadLocal.withInitial(() -> q.acquireAppender());
    int size=1000;
    IntStream.range(0,size).parallel().forEach(i -> writeTestDocument(tl));
    ExcerptTailer tailer=q.createTailer();
    for (int i=0; i < size; i++) {
      try (DocumentContext dc=tailer.readingDocument(false)){
        Assert.assertEquals(dc.index(),dc.wire().read(() -> "String_Node_Str").int64());
      }
     }
  }
 }

Fixed version (ground truth):
@Test public void testAppendedSkipToEndMultiThreaded() throws TimeoutException, ExecutionException, InterruptedException {
}
Program: 52148
Project: 52148
Buggy source:
private void writeTestDocument(ThreadLocal<ExcerptAppender> tl){
  try (DocumentContext dc=tl.get().writingDocument()){
    long index=dc.index();
    System.out.println("String_Node_Str" + index);
    dc.wire().write("String_Node_Str").int64(index);
  }
 }

Fixed version (ground truth):
private void writeTestDocument(ThreadLocal<ExcerptAppender> tl){
  try (DocumentContext dc=tl.get().writingDocument()){
    long index=dc.index();
    dc.wire().write("String_Node_Str").int64(index);
    lastPosition.set(dc.wire().bytes().writePosition());
    lastIndex.set(dc.index());
  }
 }
Program: 52149
Project: 52149
Buggy source:
/** 
 * @return creates a new instance of mapped bytes, because, for example thetailer and appender can be at different locations.
 */
@NotNull @Override public MappedBytes bytes(){
  return MappedBytes.mappedBytes(mappedFile);
}

Fixed version (ground truth):
/** 
 * @return creates a new instance of mapped bytes, because, for example the tailer and appendercan be at different locations.
 */
@NotNull @Override public MappedBytes bytes(){
  return MappedBytes.mappedBytes(mappedFile);
}
Program: 52150
Project: 52150
Buggy source:
@Override public void executeQuery(String query,Class<? extends Marshallable> resultType,Object... args){
  try (PreparedStatement ps=connection.prepareStatement(query)){
    for (int i=0; i < args.length; i++)     ps.setObject(i + 1,args[i]);
    ResultSet resultSet=ps.executeQuery();
    ResultSetMetaData metaData=resultSet.getMetaData();
    int columnCount=metaData.getColumnCount();
    result.queryResult(new Iterator<Marshallable>(){
      @Override public boolean hasNext(){
        try {
          return resultSet.next();
        }
 catch (        SQLException e) {
          throw Jvm.rethrow(e);
        }
      }
      @Override public Marshallable next(){
        return new Marshallable(){
          @Override public void writeMarshallable(          @NotNull WireOut wire){
            try {
              for (int i=1; i <= columnCount; i++) {
                wire.writeEventName(metaData.getCatalogName(i)).object(resultSet.getObject(i));
              }
            }
 catch (            SQLException e) {
              throw Jvm.rethrow(e);
            }
          }
        }
;
      }
    }
,query,args);
  }
 catch (  Throwable t) {
    result.queryThrown(t,query,args);
  }
}

Fixed version (ground truth):
@Override public void executeQuery(String query,Object... args){
  try (PreparedStatement ps=connection.prepareStatement(query)){
    for (int i=0; i < args.length; i++)     ps.setObject(i + 1,args[i]);
    ResultSet resultSet=ps.executeQuery();
    ResultSetMetaData metaData=resultSet.getMetaData();
    int columnCount=metaData.getColumnCount();
    List<String> headings=new ArrayList<>(columnCount);
    for (int i=1; i <= columnCount; i++)     headings.add(metaData.getColumnName(i));
    List<List<Object>> rows=new ArrayList<>();
    while (resultSet.next()) {
      List<Object> row=new ArrayList<>(columnCount);
      for (int i=1; i <= columnCount; i++) {
        row.add(resultSet.getObject(i));
      }
      rows.add(row);
    }
    result.queryResult(headings,rows,query,args);
  }
 catch (  Throwable t) {
    result.queryThrown(t,query,args);
  }
}
Program: 52151
Project: 52151
Buggy source:
void queryResult(Iterator<Marshallable> marshallableList,String query,Object... args);

Fixed version (ground truth):
void queryResult(List<String> columns,List<List<Object>> rows,String query,Object... args);
Program: 52152
Project: 52152
Buggy source:
void executeQuery(String query,Class<? extends Marshallable> resultType,Object... args);

Fixed version (ground truth):
void executeQuery(String query,Object... args);
Program: 52153
Project: 52153
Buggy source:
@Override public long recoverAndWriteHeader(Wire wire,int length,long timeoutMS) throws UnrecoverableTimeoutException {
  while (true) {
    Jvm.warn().on(getClass(),"String_Node_Str" + Long.toHexString(wire.headerNumber()) + "String_Node_Str"+ wire.bytes().writePosition());
    try {
      return wire.writeHeader(length,timeoutMS,TimeUnit.MILLISECONDS);
    }
 catch (    TimeoutException e) {
      Jvm.warn().on(getClass(),e);
    }
catch (    EOFException e) {
      throw new AssertionError(e);
    }
  }
}

Fixed version (ground truth):
@Override public long recoverAndWriteHeader(Wire wire,int length,long timeoutMS) throws UnrecoverableTimeoutException {
  while (true) {
    long offset=wire.bytes().writePosition();
    int num=wire.bytes().readInt(offset);
    if (Wires.isNotComplete(num) && wire.bytes().compareAndSwapInt(offset,num,0)) {
      Jvm.warn().on(getClass(),"String_Node_Str" + Long.toHexString(wire.headerNumber()) + "String_Node_Str"+ offset+ "String_Node_Str");
    }
 else {
      Jvm.warn().on(getClass(),"String_Node_Str" + Long.toHexString(wire.headerNumber()) + "String_Node_Str"+ offset+ "String_Node_Str");
    }
    try {
      return wire.writeHeader(length,timeoutMS,TimeUnit.MILLISECONDS);
    }
 catch (    TimeoutException e) {
      Jvm.warn().on(getClass(),e);
    }
catch (    EOFException e) {
      throw new AssertionError(e);
    }
  }
}
Program: 52154
Project: 52154
Buggy source:
@Test(expected=UnsupportedOperationException.class) public void testZeroLengthMessage(){
  File tmpDir=getTmpDir();
  try (ChronicleQueue chronicle=SingleChronicleQueueBuilder.binary(tmpDir).wireType(this.wireType).build()){
    ExcerptAppender appender=chronicle.createAppender();
    appender.writeDocument(w -> {
    }
);
    System.out.println(chronicle.dump());
  }
 }

Fixed version (ground truth):
@Test public void testZeroLengthMessage(){
  File tmpDir=getTmpDir();
  try (ChronicleQueue chronicle=SingleChronicleQueueBuilder.binary(tmpDir).rollCycle(RollCycles.TEST_DAILY).wireType(this.wireType).build()){
    ExcerptAppender appender=chronicle.createAppender();
    appender.writeDocument(w -> {
    }
);
    System.out.println(chronicle.dump());
    ExcerptTailer tailer=chronicle.createTailer();
    try (DocumentContext dc=tailer.readingDocument()){
      assertFalse(dc.wire().hasMore());
    }
   }
 }
Program: 52155
Project: 52155
Buggy source:
@Ignore("String_Node_Str") @Test public void testAppendAndRead() throws TimeoutException, ExecutionException, InterruptedException {
}

Fixed version (ground truth):
@Test public void testAppendAndRead() throws TimeoutException, ExecutionException, InterruptedException {
}
Program: 52156
Project: 52156
Buggy source:
@Override public void dump(Writer writer,long fromIndex,long toIndex){
  try {
    long firstIndex=firstIndex();
    writer.append("String_Node_Str").append(Long.toHexString(firstIndex)).append("String_Node_Str");
    writer.append("String_Node_Str").append(Long.toHexString(lastIndex())).append("String_Node_Str");
    ExcerptTailer tailer=createTailer();
    if (!tailer.moveToIndex(fromIndex)) {
      if (firstIndex > fromIndex) {
        tailer.toStart();
      }
 else {
        return;
      }
    }
    Bytes bytes=Wires.acquireBytes();
    TextWire text=new TextWire(bytes);
    while (true) {
      try (DocumentContext dc=tailer.readingDocument()){
        if (!dc.isPresent()) {
          writer.append("String_Node_Str").append(Long.toHexString(dc.index())).append("String_Node_Str");
          return;
        }
        if (dc.index() > toIndex)         return;
        writer.append("String_Node_Str").append(Long.toHexString(dc.index())).append("String_Node_Str");
        Wire wire=dc.wire();
        long start=wire.bytes().readPosition();
        try {
          text.clear();
          wire.copyTo(text);
          writer.append(bytes.toString());
        }
 catch (        Exception e) {
          wire.bytes().readPosition(start);
          writer.append(wire.bytes()).append("String_Node_Str");
        }
      }
     }
  }
 catch (  Exception e) {
    e.printStackTrace(new PrintWriter(writer));
  }
}

Fixed version (ground truth):
@Override public void dump(Writer writer,long fromIndex,long toIndex){
  try {
    long firstIndex=firstIndex();
    writer.append("String_Node_Str").append(Long.toHexString(firstIndex)).append("String_Node_Str");
    writer.append("String_Node_Str").append(Long.toHexString(lastIndex())).append("String_Node_Str");
    ExcerptTailer tailer=createTailer();
    if (!tailer.moveToIndex(fromIndex)) {
      if (firstIndex > fromIndex) {
        tailer.toStart();
      }
 else {
        return;
      }
    }
    Bytes bytes=Wires.acquireBytes();
    TextWire text=new TextWire(bytes);
    while (true) {
      try (DocumentContext dc=tailer.readingDocument()){
        if (!dc.isPresent()) {
          writer.append("String_Node_Str").append(Long.toHexString(dc.index())).append("String_Node_Str");
          return;
        }
        if (dc.index() > toIndex)         return;
        writer.append("String_Node_Str").append(Long.toHexString(dc.index())).append("String_Node_Str");
        Wire wire=dc.wire();
        long start=wire.bytes().readPosition();
        try {
          text.clear();
          wire.copyTo(text);
          writer.append(bytes.toString());
        }
 catch (        Exception e) {
          wire.bytes().readPosition(start);
          writer.append(wire.bytes()).append("String_Node_Str");
        }
      }
     }
  }
 catch (  Exception e) {
    e.printStackTrace(new PrintWriter(writer));
  }
 finally {
    try {
      writer.flush();
    }
 catch (    IOException ignore) {
    }
  }
}
Program: 52157
Project: 52157
Buggy source:
long acquireIndex2Index(Wire wire,long timeoutMS) throws EOFException, TimeoutException {
  long start=System.currentTimeMillis();
  try {
    do {
      long index2Index=this.index2Index.getVolatileValue();
      if (index2Index == LONG_NOT_COMPLETE) {
        wire.pauser().pause(timeoutMS,TimeUnit.MILLISECONDS);
        continue;
      }
      if (index2Index != NOT_INITIALIZED)       return index2Index;
      if (!this.index2Index.compareAndSwapValue(NOT_INITIALIZED,LONG_NOT_COMPLETE))       continue;
      long index=NOT_INITIALIZED;
      try {
        index=newIndex(wire,true,timeoutMS);
      }
  finally {
        this.index2Index.setOrderedValue(index);
      }
      return index;
    }
 while (System.currentTimeMillis() < start + timeoutMS);
  }
  finally {
    wire.pauser().reset();
  }
  throw new IllegalStateException("String_Node_Str");
}

Fixed version (ground truth):
long acquireIndex2Index(Wire wire,long timeoutMS) throws EOFException, TimeoutException {
  try {
    return acquireIndex2Index0(wire,timeoutMS);
  }
 catch (  TimeoutException te) {
    LOG.warn("String_Node_Str" + te);
    this.index2Index.setValue(0);
    return acquireIndex2Index0(wire,timeoutMS);
  }
}