nus-yam/ex-repair huggingface dataset:
Program: 52158
Project: 52158
Buggy source:
long newIndex(Wire wire,LongArrayValues index2Index,long index2,long timeoutMS) throws EOFException, TimeoutException {
  try {
    if (index2Index.compareAndSet(index2,NOT_INITIALIZED,LONG_NOT_COMPLETE)) {
      long pos=newIndex(wire,false,timeoutMS);
      if (pos < 0)       throw new IllegalStateException("String_Node_Str" + pos);
      if (index2Index.compareAndSet(index2,LONG_NOT_COMPLETE,pos)) {
        index2Index.setMaxUsed(index2 + 1);
        return pos;
      }
      throw new IllegalStateException("String_Node_Str" + index2 + "String_Node_Str");
    }
    for (; ; ) {
      long pos=index2Index.getVolatileValueAt(index2);
      if (pos == LONG_NOT_COMPLETE) {
        wire.pauser().pause(timeoutMS,TimeUnit.MILLISECONDS);
      }
 else {
        wire.pauser().reset();
        return pos;
      }
    }
  }
 catch (  Exception e) {
    index2Index.compareAndSet(index2,LONG_NOT_COMPLETE,NOT_INITIALIZED);
    throw e;
  }
}

Fixed version (ground truth):
long newIndex(Wire wire,LongArrayValues index2Index,long index2,long timeoutMS) throws EOFException, TimeoutException {
  try {
    if (index2Index.compareAndSet(index2,NOT_INITIALIZED,BinaryLongReference.LONG_NOT_COMPLETE)) {
      long pos=newIndex(wire,false,timeoutMS);
      if (pos < 0)       throw new IllegalStateException("String_Node_Str" + pos);
      if (index2Index.compareAndSet(index2,BinaryLongReference.LONG_NOT_COMPLETE,pos)) {
        index2Index.setMaxUsed(index2 + 1);
        return pos;
      }
      throw new IllegalStateException("String_Node_Str" + index2 + "String_Node_Str");
    }
    for (; ; ) {
      long pos=index2Index.getVolatileValueAt(index2);
      if (pos == BinaryLongReference.LONG_NOT_COMPLETE) {
        wire.pauser().pause(timeoutMS,TimeUnit.MILLISECONDS);
      }
 else {
        wire.pauser().reset();
        return pos;
      }
    }
  }
 catch (  Exception e) {
    index2Index.compareAndSet(index2,BinaryLongReference.LONG_NOT_COMPLETE,NOT_INITIALIZED);
    throw e;
  }
}
Program: 52159
Project: 52159
Buggy source:
private long getSecondaryAddress0(Wire wire,long timeoutMS,LongArrayValues index2indexArr,int index2) throws TimeoutException {
  long secondaryAddress;
  while (true) {
    secondaryAddress=index2indexArr.getVolatileValueAt(index2);
    if (secondaryAddress == LONG_NOT_COMPLETE) {
      wire.pauser().pause(timeoutMS,TimeUnit.MILLISECONDS);
    }
 else {
      if (secondaryAddress > wire.bytes().capacity())       throw new IllegalStateException("String_Node_Str" + secondaryAddress);
      wire.pauser().reset();
      break;
    }
  }
  return secondaryAddress;
}

Fixed version (ground truth):
private long getSecondaryAddress0(Wire wire,long timeoutMS,LongArrayValues index2indexArr,int index2) throws TimeoutException {
  long secondaryAddress;
  while (true) {
    secondaryAddress=index2indexArr.getVolatileValueAt(index2);
    if (secondaryAddress == BinaryLongReference.LONG_NOT_COMPLETE) {
      wire.pauser().pause(timeoutMS,TimeUnit.MILLISECONDS);
    }
 else {
      if (secondaryAddress > wire.bytes().capacity())       throw new IllegalStateException("String_Node_Str" + secondaryAddress);
      wire.pauser().reset();
      break;
    }
  }
  return secondaryAddress;
}
Program: 52160
Project: 52160
Buggy source:
long getSecondaryAddress(Wire wire,long timeoutMS,LongArrayValues index2indexArr,int index2) throws EOFException, TimeoutException {
  long secondaryAddress=index2indexArr.getValueAt(index2);
  if (secondaryAddress == 0) {
    secondaryAddress=newIndex(wire,index2indexArr,index2,timeoutMS);
    if (secondaryAddress > wire.bytes().capacity())     throw new IllegalStateException("String_Node_Str" + secondaryAddress);
    long sa=index2indexArr.getValueAt(index2);
    if (sa != secondaryAddress)     throw new AssertionError();
  }
 else   if (secondaryAddress == LONG_NOT_COMPLETE) {
    secondaryAddress=getSecondaryAddress0(wire,timeoutMS,index2indexArr,index2);
  }
 else   if (secondaryAddress > wire.bytes().capacity()) {
    throw new IllegalStateException("String_Node_Str" + secondaryAddress);
  }
  return secondaryAddress;
}

Fixed version (ground truth):
long getSecondaryAddress(Wire wire,long timeoutMS,LongArrayValues index2indexArr,int index2) throws EOFException, TimeoutException {
  long secondaryAddress=index2indexArr.getValueAt(index2);
  if (secondaryAddress == 0) {
    secondaryAddress=newIndex(wire,index2indexArr,index2,timeoutMS);
    if (secondaryAddress > wire.bytes().capacity())     throw new IllegalStateException("String_Node_Str" + secondaryAddress);
    long sa=index2indexArr.getValueAt(index2);
    if (sa != secondaryAddress)     throw new AssertionError();
  }
 else   if (secondaryAddress == BinaryLongReference.LONG_NOT_COMPLETE) {
    secondaryAddress=getSecondaryAddress0(wire,timeoutMS,index2indexArr,index2);
  }
 else   if (secondaryAddress > wire.bytes().capacity()) {
    throw new IllegalStateException("String_Node_Str" + secondaryAddress);
  }
  return secondaryAddress;
}
Program: 52161
Project: 52161
Buggy source:
/** 
 * tests that when flags are set to not complete we are able to recover
 */
@Test public void testUsingANotCompleteQueue() throws TimeoutException, ExecutionException, InterruptedException {
  File tmpDir=getTmpDir();
  try (final RollingChronicleQueue queue=new SingleChronicleQueueBuilder(tmpDir).wireType(WireType.BINARY).build()){
    ExcerptAppender appender=queue.createAppender();
    try (DocumentContext documentContext=appender.writingDocument()){
      documentContext.wire().write("String_Node_Str").text("String_Node_Str");
    }
     Thread.sleep(100);
    System.out.println(queue.dump());
  }
   BinaryLongReference.forceAllToNotCompleteState();
  try (final RollingChronicleQueue queue=new SingleChronicleQueueBuilder(tmpDir).wireType(WireType.BINARY).build()){
    ExcerptTailer tailer=queue.createTailer();
    try (DocumentContext documentContext=tailer.readingDocument()){
      Assert.assertEquals("String_Node_Str",documentContext.wire().read(() -> "String_Node_Str").text());
    }
   }
 }

Fixed version (ground truth):
/** 
 * tests that when flags are set to not complete we are able to recover
 */
@Test public void testUsingANotCompleteQueue() throws TimeoutException, ExecutionException, InterruptedException {
  BinaryLongReference.startCollecting();
  File tmpDir=getTmpDir();
  try (final RollingChronicleQueue queue=new SingleChronicleQueueBuilder(tmpDir).wireType(WireType.BINARY).build()){
    ExcerptAppender appender=queue.createAppender();
    try (DocumentContext documentContext=appender.writingDocument()){
      documentContext.wire().write("String_Node_Str").text("String_Node_Str");
    }
     Thread.sleep(100);
    System.out.println(queue.dump());
  }
   BinaryLongReference.forceAllToNotCompleteState();
  try (final RollingChronicleQueue queue=new SingleChronicleQueueBuilder(tmpDir).wireType(WireType.BINARY).timeoutMS(500).build()){
    System.out.println(queue.dump());
    ExcerptTailer tailer=queue.createTailer();
    try (DocumentContext documentContext=tailer.readingDocument()){
      Assert.assertEquals("String_Node_Str",documentContext.wire().read(() -> "String_Node_Str").text());
    }
   }
 }
Program: 52162
Project: 52162
Buggy source:
long getSecondaryAddress(Wire wire,long timeoutMS,LongArrayValues index2indexArr,int index2) throws EOFException, TimeoutException {
  long secondaryAddress=index2indexArr.getValueAt(index2);
  if (secondaryAddress == 0) {
    secondaryAddress=newIndex(wire,index2indexArr,index2,timeoutMS);
    if (secondaryAddress > wire.bytes().capacity())     throw new IllegalStateException("String_Node_Str" + secondaryAddress);
    long sa=index2indexArr.getValueAt(index2);
    if (sa != secondaryAddress)     throw new AssertionError();
  }
 else   if (secondaryAddress == BinaryLongReference.LONG_NOT_COMPLETE) {
    secondaryAddress=getSecondaryAddress0(wire,timeoutMS,index2indexArr,index2);
  }
 else   if (secondaryAddress > wire.bytes().capacity()) {
    throw new IllegalStateException("String_Node_Str" + secondaryAddress);
  }
  return secondaryAddress;
}

Fixed version (ground truth):
long getSecondaryAddress(Wire wire,long timeoutMS,LongArrayValues index2indexArr,int index2) throws EOFException, TimeoutException {
  try {
    return getSecondaryAddress1(wire,timeoutMS,index2indexArr,index2);
  }
 catch (  TimeoutException e) {
    LOG.warn("String_Node_Str" + index2 + "String_Node_Str"+ e);
    index2indexArr.setValueAt(index2,0L);
    return getSecondaryAddress1(wire,timeoutMS,index2indexArr,index2);
  }
}
Program: 52163
Project: 52163
Buggy source:
@Test(expected=UnsupportedOperationException.class) public void testZeroLengthMessage(){
}

Fixed version (ground truth):
@Test(expected=UnsupportedOperationException.class) public void testZeroLengthMessage(){
  File tmpDir=getTmpDir();
  try (ChronicleQueue chronicle=new SingleChronicleQueueBuilder(tmpDir).wireType(this.wireType).build()){
    ExcerptAppender appender=chronicle.createAppender();
    appender.writeDocument(w -> {
    }
);
    System.out.println(chronicle.dump());
  }
 }
Program: 52164
Project: 52164
Buggy source:
/** 
 * tests that when flags are set to not complete we are able to recover
 */
@Test public void testUsingANotCompleteQueue() throws TimeoutException, ExecutionException, InterruptedException {
  BinaryLongReference.startCollecting();
  File tmpDir=getTmpDir();
  try (final RollingChronicleQueue queue=new SingleChronicleQueueBuilder(tmpDir).wireType(WireType.BINARY).build()){
    ExcerptAppender appender=queue.createAppender();
    try (DocumentContext documentContext=appender.writingDocument()){
      documentContext.wire().write("String_Node_Str").text("String_Node_Str");
    }
     Thread.sleep(100);
    System.out.println(queue.dump());
  }
   BinaryLongReference.forceAllToNotCompleteState();
  try (final RollingChronicleQueue queue=new SingleChronicleQueueBuilder(tmpDir).wireType(WireType.BINARY).timeoutMS(500).build()){
    System.out.println(queue.dump());
    ExcerptTailer tailer=queue.createTailer();
    try (DocumentContext documentContext=tailer.readingDocument()){
      Assert.assertEquals("String_Node_Str",documentContext.wire().read(() -> "String_Node_Str").text());
    }
   }
 }

Fixed version (ground truth):
/** 
 * tests that when flags are set to not complete we are able to recover
 */
@Test public void testUsingANotCompleteQueue() throws TimeoutException, ExecutionException, InterruptedException {
  BinaryLongReference.startCollecting();
  File tmpDir=getTmpDir();
  try (final RollingChronicleQueue queue=new SingleChronicleQueueBuilder(tmpDir).wireType(WireType.BINARY).rollCycle(RollCycles.TEST_DAILY).build()){
    ExcerptAppender appender=queue.createAppender();
    try (DocumentContext documentContext=appender.writingDocument()){
      documentContext.wire().write("String_Node_Str").text("String_Node_Str");
    }
     Thread.sleep(100);
    System.out.println(queue.dump());
  }
   BinaryLongReference.forceAllToNotCompleteState();
  try (final RollingChronicleQueue queue=new SingleChronicleQueueBuilder(tmpDir).wireType(WireType.BINARY).timeoutMS(500).build()){
    System.out.println(queue.dump());
    ExcerptTailer tailer=queue.createTailer();
    try (DocumentContext documentContext=tailer.readingDocument()){
      Assert.assertEquals("String_Node_Str",documentContext.wire().read(() -> "String_Node_Str").text());
    }
   }
 }
Program: 52165
Project: 52165
Buggy source:
private boolean next() throws TimeoutException {
  if (this.store == null) {
    final long firstIndex=queue.firstIndex();
    if (firstIndex == Long.MAX_VALUE)     return false;
    if (!this.moveToIndex(firstIndex))     return false;
  }
  Bytes<?> bytes=wire.bytes();
  bytes.readLimit(bytes.capacity());
  for (int i=0; i < 1000; i++) {
    try {
      if (direction != TailerDirection.FORWARD)       try {
        moveToIndex(index);
      }
 catch (      TimeoutException notReady) {
        return false;
      }
      if (wire.readDataHeader()) {
        closeReadLimit(bytes.capacity());
        wire.readAndSetLength(bytes.readPosition());
        long end=bytes.readLimit();
        closeReadPosition(end);
        return true;
      }
      return false;
    }
 catch (    EOFException eof) {
      if (cycle <= queue.lastCycle() && direction != TailerDirection.NONE)       try {
        if (moveToIndex(cycle + direction.add(),0)) {
          bytes=wire.bytes();
          continue;
        }
      }
 catch (      TimeoutException failed) {
      }
      return false;
    }
  }
  throw new IllegalStateException("String_Node_Str");
}

Fixed version (ground truth):
private boolean next(boolean includeMetaData) throws TimeoutException {
  if (this.store == null) {
    final long firstIndex=queue.firstIndex();
    if (firstIndex == Long.MAX_VALUE)     return false;
    if (!this.moveToIndex(firstIndex))     return false;
  }
  Bytes<?> bytes=wire.bytes();
  bytes.readLimit(bytes.capacity());
  for (int i=0; i < 1000; i++) {
    try {
      if (direction != TailerDirection.FORWARD)       try {
        moveToIndex(index);
      }
 catch (      TimeoutException notReady) {
        return false;
      }
switch (wire.readDataHeader(includeMetaData)) {
case NONE:
        return false;
case META_DATA:
      metaData(true);
    break;
case DATA:
  metaData(false);
break;
}
closeReadLimit(bytes.capacity());
wire.readAndSetLength(bytes.readPosition());
long end=bytes.readLimit();
closeReadPosition(end);
return true;
}
 catch (EOFException eof) {
if (cycle <= queue.lastCycle() && direction != TailerDirection.NONE) try {
if (moveToIndex(cycle + direction.add(),0)) {
bytes=wire.bytes();
continue;
}
}
 catch (TimeoutException failed) {
}
return false;
}
}
throw new IllegalStateException("String_Node_Str");
}
Program: 52166
Project: 52166
Buggy source:
@Override public DocumentContext readingDocument(boolean includeMetaData){
  while (true) {
    try {
      present=next();
    }
 catch (    TimeoutException ignored) {
      present=false;
    }
    if (present) {
      if (!includeMetaData && isMetaData()) {
        close();
        continue;
      }
      return this;
    }
    return NoDocumentContext.INSTANCE;
  }
}

Fixed version (ground truth):
@Override public DocumentContext readingDocument(boolean includeMetaData){
  try {
    if (present=next(includeMetaData))     return this;
  }
 catch (  TimeoutException ignored) {
  }
  return NoDocumentContext.INSTANCE;
}
Program: 52167
Project: 52167
Buggy source:
/** 
 * Write a Map as a marshallable
 */
default void writeMap(Map<String,Object> map){
  QueueInternal.writeMap(this,map);
}

Fixed version (ground truth):
/** 
 * Write a Map as a marshallable
 */
default void writeMap(Map<String,?> map){
  QueueInternal.writeMap(this,map);
}
Program: 52168
Project: 52168
Buggy source:
@Override public DocumentContext writingDocument(){
  try {
    position=wire.writeHeader(queue.timeoutMS,TimeUnit.MILLISECONDS);
    metaData=false;
  }
 catch (  TimeoutException e) {
    throw new IllegalStateException(e);
  }
catch (  EOFException e) {
    throw new UnsupportedOperationException("String_Node_Str");
  }
  return this;
}

Fixed version (ground truth):
@Override public DocumentContext writingDocument(){
}
Program: 52169
Project: 52169
Buggy source:
@Override public boolean readDocument(@NotNull final ReadMarshallable marshaller){
  try {
    return read(marshaller,ReadMarshallable::readMarshallable,queue.timeoutMS);
  }
 catch (  TimeoutException e) {
    return false;
  }
}

Fixed version (ground truth):
@Override public boolean readDocument(@NotNull final ReadMarshallable marshaller){
  return read(marshaller,ReadMarshallable::readMarshallable);
}
Program: 52170
Project: 52170
Buggy source:
private boolean checkAppendingThread(){
  Thread appendingThread=this.appendingThread;
  if (appendingThread != null)   throw new IllegalStateException("String_Node_Str" + Thread.currentThread() + "String_Node_Str"+ appendingThread);
  this.appendingThread=Thread.currentThread();
  return true;
}

Fixed version (ground truth):
private boolean checkAppendingThread(){
  Thread appendingThread=this.appendingThread;
  Thread currentThread=Thread.currentThread();
  if (appendingThread != null) {
    if (appendingThread == currentThread)     throw new IllegalStateException("String_Node_Str");
    throw new IllegalStateException("String_Node_Str" + currentThread + "String_Node_Str"+ appendingThread);
  }
  this.appendingThread=currentThread;
  return true;
}
Program: 52171
Project: 52171
Buggy source:
private <T>boolean read(@NotNull final T t,@NotNull final BiConsumer<T,Wire> c,long timeoutMS) throws TimeoutException {
  if (this.store == null) {
    toStart();
    if (this.store == null)     return false;
  }
  if (read0(t,c)) {
    incrementIndex();
    return true;
  }
  return false;
}

Fixed version (ground truth):
private <T>boolean read(@NotNull final T t,@NotNull final BiConsumer<T,Wire> c){
  if (this.store == null) {
    toStart();
    if (this.store == null)     return false;
  }
  if (read0(t,c)) {
    incrementIndex();
    return true;
  }
  return false;
}
Program: 52172
Project: 52172
Buggy source:
@Nullable public boolean readText(StringBuilder sb){
  try {
    if (read(sb,(t,w) -> w.bytes().parseUtf8(sb,(int)w.bytes().readRemaining()),queue.timeoutMS))     return true;
  }
 catch (  TimeoutException e) {
  }
  sb.setLength(0);
  sb.append("String_Node_Str");
  return false;
}

Fixed version (ground truth):
@Nullable public boolean readText(StringBuilder sb){
  if (read(sb,(t,w) -> w.bytes().parseUtf8(sb,(int)w.bytes().readRemaining())))   return true;
  sb.setLength(0);
  sb.append("String_Node_Str");
  return false;
}
Program: 52173
Project: 52173
Buggy source:
@Override public boolean readBytes(@NotNull final ReadBytesMarshallable using){
  try {
    return read(using,(t,w) -> t.readMarshallable(w.bytes()),queue.timeoutMS);
  }
 catch (  TimeoutException e) {
    return false;
  }
}

Fixed version (ground truth):
@Override public boolean readBytes(@NotNull final ReadBytesMarshallable using){
  return read(using,(t,w) -> t.readMarshallable(w.bytes()));
}
Program: 52174
Project: 52174
Buggy source:
@Override public long lastIndexAppended(){
  if (lastIndex != Long.MIN_VALUE)   return lastIndex;
  if (this.position == -1)   throw new IllegalStateException("String_Node_Str");
  try {
    long sequenceNumber=store.indexForPosition(wire,position,queue.timeoutMS);
    final long index=queue.rollCycle().toIndex(cycle,sequenceNumber);
    return index;
  }
 catch (  EOFException|TimeoutException e) {
    throw new AssertionError(e);
  }
 finally {
    wire.bytes().writePosition(store.writePosition());
  }
}

Fixed version (ground truth):
@Override public long lastIndexAppended(){
  if (lastIndex != Long.MIN_VALUE)   return lastIndex;
  if (this.position == -1)   throw new IllegalStateException("String_Node_Str");
  try {
    long sequenceNumber=store.indexForPosition(wire,position,queue.timeoutMS);
    lastIndex=queue.rollCycle().toIndex(cycle,sequenceNumber);
    return lastIndex;
  }
 catch (  EOFException|TimeoutException e) {
    throw new AssertionError(e);
  }
 finally {
    wire.bytes().writePosition(store.writePosition());
  }
}
Program: 52175
Project: 52175
Buggy source:
private void rollCycleTo(int cycle) throws TimeoutException {
  wire.writeEndOfWire(queue.timeoutMS,TimeUnit.MILLISECONDS);
  setCycle2(cycle);
}

Fixed version (ground truth):
private void rollCycleTo(int cycle) throws TimeoutException {
  if (wire != null)   wire.writeEndOfWire(queue.timeoutMS,TimeUnit.MILLISECONDS);
  setCycle2(cycle);
}
Program: 52176
Project: 52176
Buggy source:
public StoreAppender(@NotNull SingleChronicleQueue queue){
  this.queue=queue;
  int cycle=this.queue.lastCycle();
  if (cycle < 0)   cycle=queue.cycle();
  setCycle2(cycle);
}

Fixed version (ground truth):
public StoreAppender(@NotNull SingleChronicleQueue queue){
  this.queue=queue;
}
Program: 52177
Project: 52177
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 net.openhft.chronicle.queue.impl.single.SingleChronicleQueueStore.Indexing#moveToIndex
 */
private ScanResult linearScan(@NotNull final Wire wire,final long toIndex,final long fromKnownIndex,final long knownAddress){
  @NotNull final Bytes<?> bytes=wire.bytes();
  bytes.readLimit(writePosition.getValue()).readPosition(knownAddress);
  for (long i=fromKnownIndex; ; i++) {
    try {
      if (bytes.readRemaining() < 4)       return ScanResult.NOT_REACHED;
      if (wire.readDataHeader()) {
        if (i == toIndex)         return ScanResult.FOUND;
        bytes.readSkip(Wires.lengthOf(bytes.readInt()));
        continue;
      }
    }
 catch (    EOFException e) {
    }
    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 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 net.openhft.chronicle.queue.impl.single.SingleChronicleQueueStore.Indexing#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 e) {
    }
    return i == toIndex ? ScanResult.NOT_FOUND : ScanResult.NOT_REACHED;
  }
}
Program: 52178
Project: 52178
Buggy source:
public long lastIndex(int cycle){
  cycle(cycle);
  long sequenceNumber=store.lastEntryIndexed(wire,queue.timeoutMS);
  return queue.rollCycle().toIndex(this.cycle,sequenceNumber);
}

Fixed version (ground truth):
public long lastIndex(int cycle){
  cycle(cycle);
  long sequenceNumber=store.lastEntryIndexed(wire,queue.timeoutMS);
  return queue.rollCycle().toIndex(this.cycle,sequenceNumber + 1) - 1;
}
Program: 52179
Project: 52179
Buggy source:
@NotNull @Override public ExcerptTailer toEnd(){
  long index=queue.lastIndex();
  if (index == Long.MIN_VALUE)   return this;
  try {
    if (direction == TailerDirection.FORWARD)     index++;
    moveToIndex(index);
  }
 catch (  TimeoutException e) {
    throw new AssertionError(e);
  }
  return this;
}

Fixed version (ground truth):
@NotNull @Override public ExcerptTailer toEnd(){
  long index=queue.lastIndex();
  if (index == Long.MIN_VALUE)   return this;
  try {
    if (direction == TailerDirection.FORWARD || queue.rollCycle().toSequenceNumber(index + 1) == 0)     index++;
    moveToIndex(index);
  }
 catch (  TimeoutException e) {
    throw new AssertionError(e);
  }
  return this;
}
Program: 52180
Project: 52180
Buggy source:
@Test public void toEndBeforeWriteTest(){
  String baseDir=OS.TARGET + "String_Node_Str";
  IOTools.shallowDeleteDirWithFiles(baseDir);
  ChronicleQueue queue=new SingleChronicleQueueBuilder(baseDir).build();
  checkOneFile(baseDir);
  ExcerptAppender appender=queue.createAppender();
  checkOneFile(baseDir);
  ExcerptTailer tailer=queue.createTailer();
  checkOneFile(baseDir);
  ExcerptTailer tailer2=queue.createTailer();
  checkOneFile(baseDir);
  tailer.toEnd();
  tailer2.toEnd();
  checkOneFile(baseDir);
  IOTools.shallowDeleteDirWithFiles(baseDir);
}

Fixed version (ground truth):
@Test public void toEndBeforeWriteTest(){
  String baseDir=OS.TARGET + "String_Node_Str";
  IOTools.shallowDeleteDirWithFiles(baseDir);
  ChronicleQueue queue=new SingleChronicleQueueBuilder(baseDir).build();
  checkOneFile(baseDir);
  ExcerptAppender appender=queue.createAppender();
  checkOneFile(baseDir);
  ExcerptTailer tailer=queue.createTailer();
  checkOneFile(baseDir);
  ExcerptTailer tailer2=queue.createTailer();
  checkOneFile(baseDir);
  tailer.toEnd();
  checkOneFile(baseDir);
  tailer2.toEnd();
  checkOneFile(baseDir);
  IOTools.shallowDeleteDirWithFiles(baseDir);
}
Program: 52181
Project: 52181
Buggy source:
/** 
 * A Tailer can be used to read sequentially from the lower of a given position.
 * @return ExcerptTailer
 * @throws IOException if an IO problem occurs
 */
@NotNull ExcerptTailer createTailer() throws IOException ;

Fixed version (ground truth):
/** 
 * A Tailer can be used to read sequentially from the lower of a given position.
 * @return ExcerptTailer
 */
@NotNull ExcerptTailer createTailer();
Program: 52182
Project: 52182
Buggy source:
DocumentContext writingDocument(boolean metaData);

Fixed version (ground truth):
DocumentContext writingDocument();
Program: 52183
Project: 52183
Buggy source:
@NotNull @Override public ExcerptTailer createTailer() throws IOException {
  return excerptFactory.createTailer(this);
}

Fixed version (ground truth):
@NotNull @Override public ExcerptTailer createTailer(){
  return excerptFactory.createTailer(this);
}
Program: 52184
Project: 52184
Buggy source:
public boolean consumeBytes(BytesConsumer consumer) throws InterruptedException {
  @NotNull final Bytes<?> bytes=wire.bytes();
  final long start=bytes.writePosition();
  bytes.writeInt(Wires.NOT_READY);
  if (!consumer.accept(bytes)) {
    bytes.writeSkip(-4);
    bytes.writeInt(bytes.writePosition(),0);
    return false;
  }
  final long len=bytes.writePosition() - start - 4;
  if (len == 0) {
    bytes.writeSkip(-4);
    bytes.writeInt(bytes.writePosition(),0);
    return false;
  }
  bytes.writeInt(start,toIntU30(len,"String_Node_Str" + "String_Node_Str"));
  store().writePosition(bytes.writePosition()).storeIndexLocation(wire,start,++index);
  return true;
}

Fixed version (ground truth):
public boolean consumeBytes(BytesConsumer consumer) throws InterruptedException {
  @NotNull final Bytes<?> bytes=wire.bytes();
  final long start=bytes.writePosition();
  bytes.writeInt(Wires.NOT_READY);
  if (!consumer.accept(bytes)) {
    bytes.writeSkip(-4);
    bytes.writeInt(bytes.writePosition(),0);
    return false;
  }
  final long len=bytes.writePosition() - start - 4;
  if (len == 0) {
    bytes.writeSkip(-4);
    bytes.writeInt(bytes.writePosition(),0);
    return false;
  }
  bytes.writeInt(start,toIntU30(len,"String_Node_Str" + "String_Node_Str"));
  store().writePosition(bytes.writePosition()).storeIndexLocation(wire,start,++sequenceNumber);
  return true;
}
Program: 52185
Project: 52185
Buggy source:
@Override public DocumentContext writingDocument(boolean metaData){
  dc.start(metaData);
  return dc;
}

Fixed version (ground truth):
@Override public DocumentContext writingDocument(){
  dc.start(false);
  return dc;
}
Program: 52186
Project: 52186
Buggy source:
@Override public void close(){
  storeTailer.index=RollingChronicleQueue.index(storeTailer.cycle,toSequenceNumber(storeTailer.index) + 1);
  dc.close();
}

Fixed version (ground truth):
@Override public void close(){
  dc.close();
}
Program: 52187
Project: 52187
Buggy source:
public void start(){
  dc.start();
  storeTailer.index=RollingChronicleQueue.index(storeTailer.cycle,toSequenceNumber(storeTailer.index) + 1);
}

Fixed version (ground truth):
public void start(){
  dc.start();
  if (isPresent())   storeTailer.index=RollingChronicleQueue.index(storeTailer.cycle,toSequenceNumber(storeTailer.index) + 1);
}
Program: 52188
Project: 52188
Buggy source:
@ForceInline private WireStore store(){
  if (cycle != queue.cycle()) {
    long nextCycle=queue.cycle();
    if (store != null) {
      while (!store.appendRollMeta(wire,nextCycle)) {
        Thread.yield();
      }
      queue.release(store);
    }
    this.cycle=nextCycle;
    this.store=queue.storeForCycle(cycle,queue.epoch());
    this.wire=queue.wireType().apply(store.mappedBytes());
    this.index=store.firstSequenceNumber();
  }
  return store;
}

Fixed version (ground truth):
@ForceInline private WireStore store(){
  if (cycle != queue.cycle()) {
    long nextCycle=queue.cycle();
    if (store != null) {
      while (!store.appendRollMeta(wire,nextCycle)) {
        Thread.yield();
      }
      queue.release(store);
    }
    this.cycle=nextCycle;
    this.store=queue.storeForCycle(cycle,queue.epoch());
    this.wire=queue.wireType().apply(store.mappedBytes());
    this.sequenceNumber=store.firstSequenceNumber();
  }
  return store;
}
Program: 52189
Project: 52189
Buggy source:
public StoreAppender(@NotNull SingleChronicleQueue queue){
  this.nextPrefetch=OS.pageSize();
  this.queue=queue;
  final long lastIndex=this.queue.lastIndex();
  this.cycle=(lastIndex == -1) ? queue.cycle() : toCycle(lastIndex);
  if (this.cycle < 0)   throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str" + cycle);
  this.store=queue.storeForCycle(this.cycle,queue.epoch());
  this.index=this.store.sequenceNumber();
  @NotNull final MappedBytes mappedBytes=store.mappedBytes();
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str" + mappedBytes.mappedFile().file().getAbsolutePath());
  wire=this.queue.wireType().apply(mappedBytes);
  dc=new AppenderDocumentContext((InternalWire)wire,this);
}

Fixed version (ground truth):
public StoreAppender(@NotNull SingleChronicleQueue queue){
  this.nextPrefetch=OS.pageSize();
  this.queue=queue;
  final long lastIndex=this.queue.lastIndex();
  this.cycle=(lastIndex == -1) ? queue.cycle() : toCycle(lastIndex);
  if (this.cycle < 0)   throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str" + cycle);
  this.store=queue.storeForCycle(this.cycle,queue.epoch());
  this.sequenceNumber=this.store.sequenceNumber();
  @NotNull final MappedBytes mappedBytes=store.mappedBytes();
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str" + mappedBytes.mappedFile().file().getAbsolutePath());
  wire=this.queue.wireType().apply(mappedBytes);
  dc=new AppenderDocumentContext((InternalWire)wire,this);
}
Program: 52190
Project: 52190
Buggy source:
private <T>long append(@NotNull WireWriter<T> wireWriter,@NotNull T writer){
  if (ASSERTIONS) {
    Thread appendingThread=this.appendingThread;
    if (appendingThread != null)     throw new IllegalStateException("String_Node_Str" + Thread.currentThread() + "String_Node_Str"+ appendingThread);
    this.appendingThread=Thread.currentThread();
  }
  WireStore store=store();
  Bytes<?> bytes=wire.bytes();
  long position=-1;
  do {
    final long readPosition=bytes.readPosition();
    final int spbHeader=bytes.readInt(readPosition);
    if ((spbHeader & Wires.META_DATA) != 0) {
      if (Wires.isReady(spbHeader)) {
        if (bytes.readInt(readPosition + SPB_HEADER_SIZE) == ROLL_KEY) {
          store=store();
          bytes=wire.bytes();
          bytes.writePosition(store.writePosition());
          bytes.readPosition(store.writePosition());
        }
      }
 else {
        continue;
      }
    }
    position=wireWriter.writeOrAdvanceIfNotEmpty(wire,false,writer);
  }
 while (position <= 0);
  index++;
  store.writePosition(bytes.writePosition());
  store.storeIndexLocation(wire,position,index);
  long index=RollingChronicleQueue.index(store.cycle(),this.index);
  if (ASSERTIONS)   appendingThread=null;
  return index;
}

Fixed version (ground truth):
private <T>long append(@NotNull WireWriter<T> wireWriter,@NotNull T writer){
  if (ASSERTIONS) {
    Thread appendingThread=this.appendingThread;
    if (appendingThread != null)     throw new IllegalStateException("String_Node_Str" + Thread.currentThread() + "String_Node_Str"+ appendingThread);
    this.appendingThread=Thread.currentThread();
  }
  WireStore store=store();
  Bytes<?> bytes=wire.bytes();
  long position=-1;
  do {
    final long readPosition=bytes.readPosition();
    final int spbHeader=bytes.readInt(readPosition);
    if ((spbHeader & Wires.META_DATA) != 0) {
      if (Wires.isReady(spbHeader)) {
        if (bytes.readInt(readPosition + SPB_HEADER_SIZE) == ROLL_KEY) {
          store=store();
          bytes=wire.bytes();
          bytes.writePosition(store.writePosition());
          bytes.readPosition(store.writePosition());
        }
      }
 else {
        continue;
      }
    }
    position=wireWriter.writeOrAdvanceIfNotEmpty(wire,false,writer);
  }
 while (position <= 0);
  sequenceNumber++;
  store.writePosition(bytes.writePosition());
  store.storeIndexLocation(wire,position,sequenceNumber);
  long index=RollingChronicleQueue.index(store.cycle(),this.sequenceNumber);
  if (ASSERTIONS)   appendingThread=null;
  return index;
}
Program: 52191
Project: 52191
Buggy source:
private long lastCycle(){
  @NotNull final String basePath=path.getAbsolutePath();
  @Nullable final File[] files=path.listFiles();
  if (files != null && files.length > 0) {
    long lastDate=Long.MIN_VALUE;
    long date;
    String name;
    for (int i=files.length - 1; i >= 0; i--) {
      try {
        name=files[i].getAbsolutePath();
        if (name.endsWith(SUFFIX)) {
          name=name.substring(basePath.length() + 1);
          name=name.substring(0,name.indexOf('.'));
          date=dateCache.parseCount(name);
          if (lastDate < date) {
            lastDate=date;
          }
        }
      }
 catch (      ParseException ignored) {
      }
    }
    return lastDate;
  }
  return -1;
}

Fixed version (ground truth):
private long lastCycle(){
  @NotNull final String basePath=path.getAbsolutePath();
  @Nullable final File[] files=path.listFiles();
  if (files != null && files.length > 0) {
    long lastDate=Long.MIN_VALUE;
    long date;
    String name;
    for (int i=files.length - 1; i >= 0; i--) {
      try {
        name=files[i].getAbsolutePath();
        if (name.endsWith(SUFFIX)) {
          name=name.substring(basePath.length() + 1);
          name=name.substring(0,name.indexOf('.'));
          date=dateCache.parseCount(name);
          if (lastDate < date) {
            lastDate=date;
          }
        }
      }
 catch (      ParseException ignored) {
      }
    }
    if (Long.MIN_VALUE == lastDate)     return -1;
    return lastDate;
  }
  return -1;
}
Program: 52192
Project: 52192
Buggy source:
/** 
 * @return if we uses a ring buffer to buffer the appends, the Excerpts arewritten to the Chronicle Queue using a background thread
 */
public boolean buffered(){
  return this.isBuffered;
}

Fixed version (ground truth):
/** 
 * @return if we uses a ring buffer to buffer the appends, the Excerpts are written to theChronicle Queue using a background thread
 */
public boolean buffered(){
  return this.isBuffered;
}
Program: 52193
Project: 52193
Buggy source:
public long writeDocument(@NotNull WriteMarshallable writer){
  final WireStore store=store();
  long position;
  do {
    position=WireInternal.writeDataOrAdvanceIfNotEmpty(wire,false,writer);
    if (position == 0)     continue;
    this.index++;
  }
 while (position <= 0);
  store.writePosition(wire.bytes().writePosition());
  store.storeIndexLocation(wire,position,index);
  return ChronicleQueue.index(store.cycle(),index);
}

Fixed version (ground truth):
public long writeDocument(@NotNull WriteMarshallable writer){
  final WireStore store=store();
  long position;
  do {
    final long readPosition=wire.bytes().readPosition();
    boolean isMetaData=(wire.bytes().readInt(readPosition) & Wires.META_DATA) != 0;
    position=WireInternal.writeDataOrAdvanceIfNotEmpty(wire,false,writer);
    if (position == 0)     continue;
    if (!isMetaData)     this.index++;
  }
 while (position < 0);
  this.index++;
  store.writePosition(wire.bytes().writePosition());
  store.storeIndexLocation(wire,position,index);
  return ChronicleQueue.index(store.cycle(),index);
}
Program: 52194
Project: 52194
Buggy source:
/** 
 * @return creates a new instance of mapped bytes, because, for example the tailer and appendercan be at different locations.
 */
@NotNull @Override public MappedBytes mappedBytes(){
  return new 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 mappedBytes(){
  final MappedBytes mappedBytes=new MappedBytes(mappedFile);
  mappedBytes.writePosition(writePosition());
  return mappedBytes;
}
Program: 52195
Project: 52195
Buggy source:
@Test(timeout=5000) public void testUnbuffered() throws IOException, InterruptedException {
}

Fixed version (ground truth):
@Test(timeout=2000) public void testUnbuffered() throws IOException, InterruptedException {
}
Program: 52196
Project: 52196
Buggy source:
@Test public void testAppendAndReadWithRolling() throws IOException {
  final ChronicleQueue queue=new SingleChronicleQueueBuilder(getTmpDir()).wireType(this.wireType).rollCycle(RollCycles.SECONDS).epoch(1452773025277L).build();
  final ExcerptAppender appender=queue.createAppender();
  for (int i=0; i < 5; i++) {
    final int n=i;
    Jvm.pause(500);
    appender.writeDocument(w -> w.write(TestKey.test).int32(n));
  }
  System.out.println("String_Node_Str");
  final ExcerptTailer tailer=queue.createTailer().toStart();
  for (int i=0; i < 5; i++) {
    final int n=i;
    final boolean condition=tailer.readDocument(r -> assertEquals(n,r.read(TestKey.test).int32()));
    assertTrue(condition);
  }
}

Fixed version (ground truth):
@Test public void testAppendAndReadWithRolling() throws IOException, InterruptedException {
  final ChronicleQueue queue=new SingleChronicleQueueBuilder(getTmpDir()).wireType(this.wireType).rollCycle(RollCycles.SECONDS).epoch(1452773025277L).build();
  final ExcerptAppender appender=queue.createAppender();
  for (int i=0; i < 5; i++) {
    final int n=i;
    Jvm.pause(500);
    appender.writeDocument(w -> w.write(TestKey.test).int32(n));
  }
  final ExcerptTailer tailer=queue.createTailer().toStart();
  for (int i=0; i < 5; i++) {
    final int n=i;
    final boolean condition=tailer.readDocument(r -> assertEquals(n,r.read(TestKey.test).int32()));
    assertTrue(condition);
  }
}
Program: 52197
Project: 52197
Buggy source:
@Test public void testReadAtIndex4MB() throws Exception {
  final File file=File.createTempFile("String_Node_Str","String_Node_Str");
  file.deleteOnExit();
  try {
    final ChronicleQueue chronicle=new SingleChronicleQueueBuilder(getTmpDir()).wireType(this.wireType).build();
    final ExcerptAppender appender=chronicle.createAppender();
    long lastIndex=-1;
    System.out.print("String_Node_Str");
    for (long i=0; i < TIMES; i++) {
      final long j=i;
      lastIndex=appender.writeDocument(wire -> wire.write(() -> "String_Node_Str").text("String_Node_Str" + j));
      if (i % (TIMES / 20) == 0) {
        System.out.println("String_Node_Str" + (i * 100 / TIMES) + "String_Node_Str");
      }
    }
    final long cycle=toCycle(lastIndex);
    final ExcerptTailer tailer=chronicle.createTailer();
    StringBuilder sb=new StringBuilder();
    for (long i=0; i < (4L << 20L); i++) {
      tailer.moveToIndex(index(cycle,i));
      tailer.readDocument(wire -> wire.read(() -> "String_Node_Str").text(sb));
      Assert.assertEquals("String_Node_Str" + i,sb.toString());
      if (i % (TIMES / 20) == 0) {
        System.out.println("String_Node_Str" + (i * 100 / TIMES) + "String_Node_Str");
      }
    }
  }
  finally {
    file.delete();
  }
}

Fixed version (ground truth):
@Ignore("String_Node_Str") @Test public void testReadAtIndex4MB() throws Exception {
  final File file=File.createTempFile("String_Node_Str","String_Node_Str");
  file.deleteOnExit();
  try {
    final ChronicleQueue chronicle=new SingleChronicleQueueBuilder(getTmpDir()).wireType(this.wireType).build();
    final ExcerptAppender appender=chronicle.createAppender();
    long lastIndex=-1;
    System.out.print("String_Node_Str");
    for (long i=0; i < TIMES; i++) {
      final long j=i;
      lastIndex=appender.writeDocument(wire -> wire.write(() -> "String_Node_Str").text("String_Node_Str" + j));
      if (i % (TIMES / 20) == 0) {
        System.out.println("String_Node_Str" + (i * 100 / TIMES) + "String_Node_Str");
      }
    }
    final long cycle=toCycle(lastIndex);
    final ExcerptTailer tailer=chronicle.createTailer();
    StringBuilder sb=new StringBuilder();
    for (long i=0; i < (4L << 20L); i++) {
      tailer.moveToIndex(index(cycle,i));
      tailer.readDocument(wire -> wire.read(() -> "String_Node_Str").text(sb));
      Assert.assertEquals("String_Node_Str" + i,sb.toString());
      if (i % (TIMES / 20) == 0) {
        System.out.println("String_Node_Str" + (i * 100 / TIMES) + "String_Node_Str");
      }
    }
  }
  finally {
    file.delete();
  }
}
Program: 52198
Project: 52198
Buggy source:
static long cycle(long index){
  int result=(int)(index >> 40L);
  if (result > (1 << 24))   throw new IllegalStateException("String_Node_Str" + "String_Node_Str");
  return result;
}

Fixed version (ground truth):
static long cycle(long index){
  int result=(int)(index >> 40L);
  if (result > (1 << 24))   throw new IllegalStateException("String_Node_Str" + "String_Node_Str");
  if (result < 0)   throw new IllegalStateException("String_Node_Str" + result + "String_Node_Str"+ "String_Node_Str");
  return result;
}
Program: 52199
Project: 52199
Buggy source:
/** 
 * @return
 */
protected abstract long cycle();

Fixed version (ground truth):
/** 
 * @return the current cycle
 */
protected abstract long cycle();
Program: 52200
Project: 52200
Buggy source:
/** 
 * @param cycle
 * @param epoch   an epoch offset as the number of number of milliseconds since January1, 1970,  00:00:00 GMT
 * @return
 * @throws IOException
 */
protected abstract WireStore storeForCycle(long cycle,final long epoch) throws IOException ;

Fixed version (ground truth):
/** 
 * @param cycle
 * @param epoch an epoch offset as the number of number of milliseconds since January 1, 1970,00:00:00 GMT
 * @return
 * @throws IOException
 */
protected abstract WireStore storeForCycle(long cycle,final long epoch) throws IOException ;
Program: 52201
Project: 52201
Buggy source:
@NotNull @Override public ExcerptTailer toStart() throws IOException {
  long firstCycle=queue.firstCycle();
  if (firstCycle > 0) {
    cycle(firstCycle);
    this.toStart=true;
  }
 else {
    this.toStart=false;
  }
  this.index=-1;
  final Bytes<?> readContext=wire.bytes();
  readContext.readPosition(0);
  readContext.readLimit(readContext.capacity());
  return this;
}

Fixed version (ground truth):
@NotNull @Override public ExcerptTailer toStart() throws IOException {
  final long index=queue.firstIndex();
  if (index == -1)   return this;
  LOG.info("String_Node_Str" + ChronicleQueue.subIndex(index) + "String_Node_Str"+ ChronicleQueue.cycle(index));
  if (!moveToIndex(index))   throw new IllegalStateException("String_Node_Str");
  return this;
}
Program: 52202
Project: 52202
Buggy source:
@Override public boolean index(long fullIndex) throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug(SingleChronicleQueueStore.IndexOffset.toBinaryString(fullIndex));
    LOG.debug(SingleChronicleQueueStore.IndexOffset.toScale());
  }
  final long nextCycle=ChronicleQueue.cycle(fullIndex);
  if (nextCycle != queue.lastCycle())   cycle(nextCycle);
  final long position=this.store.moveToIndex(wire,subIndex(fullIndex));
  final Bytes<?> readContext=wire.bytes();
  readContext.readPosition(position);
  readContext.readLimit(readContext.capacity());
  if (position != -1) {
    this.index=fullIndex - 1;
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public long index(){
  if (this.index == -1) {
    throw new IllegalStateException();
  }
  return ChronicleQueue.index(cycle(),index);
}
Program: 52203
Project: 52203
Buggy source:
private StoreTailer cycle(long cycle) throws IOException {
  if (this.cycle != cycle) {
    if (null != this.store) {
      this.queue.release(this.store);
    }
    this.cycle=cycle;
    this.index=-1;
    this.store=this.queue.storeForCycle(cycle,this.epoch);
    wire=queue.wireType().apply(store.mappedBytes());
    if (LOG.isDebugEnabled())     LOG.debug("String_Node_Str" + ((MappedBytes)wire.bytes()).mappedFile().file().getAbsolutePath());
  }
  return this;
}

Fixed version (ground truth):
private StoreTailer cycle(long cycle) throws IOException {
  if (this.cycle != cycle) {
    if (null != this.store) {
      this.queue.release(this.store);
    }
    this.cycle=cycle;
    this.index=-1;
    this.store=this.queue.storeForCycle(cycle,queue.epoch());
    wire=queue.wireType().apply(store.mappedBytes());
    if (LOG.isDebugEnabled())     LOG.debug("String_Node_Str" + ((MappedBytes)wire.bytes()).mappedFile().file().getAbsolutePath());
  }
  return this;
}
Program: 52204
Project: 52204
Buggy source:
@Override public boolean readDocument(@NotNull ReadMarshallable reader) throws IOException {
  if (this.store == null) {
    long lastCycle=this.toStart ? queue.firstCycle() : queue.lastCycle();
    if (lastCycle == -1) {
      return false;
    }
    cycle(lastCycle);
  }
  long position=store.read(wire,reader);
  if (position > 0) {
    this.index++;
    return true;
  }
 else   if (position < 0) {
    cycle(Math.abs(position));
    return readDocument(reader);
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean readDocument(@NotNull ReadMarshallable reader) throws IOException {
  if (this.store == null) {
    final long index=queue.firstIndex();
    if (index == -1) {
      return false;
    }
    moveToIndex(index);
  }
  long position=store.read(wire,reader);
  if (position > 0) {
    this.index++;
    return true;
  }
 else   if (position < 0) {
    cycle(Math.abs(position));
    return readDocument(reader);
  }
  return false;
}
Program: 52205
Project: 52205
Buggy source:
@NotNull @Override public ExcerptTailer toEnd() throws IOException {
  long cycle=queue.lastCycle();
  if (cycle > 0) {
    cycle(cycle);
  }
  this.toStart=false;
  return this;
}

Fixed version (ground truth):
@NotNull @Override public ExcerptTailer toEnd() throws IOException {
  if (!moveToIndex(queue.lastIndex()))   throw new IllegalStateException("String_Node_Str");
  return this;
}
Program: 52206
Project: 52206
Buggy source:
public StoreAppender(@NotNull AbstractChronicleQueue queue) throws IOException {
  super(queue);
  this.cycle=super.queue.lastCycle();
  if (this.cycle == -1)   this.cycle=queue.cycle();
  if (this.cycle < 0)   throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str" + cycle);
  this.store=queue.storeForCycle(this.cycle,this.epoch);
  this.index=this.store.lastIndex();
  final MappedBytes mappedBytes=store.mappedBytes();
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str" + mappedBytes.mappedFile().file().getAbsolutePath());
  wire=this.queue().wireType().apply(mappedBytes);
}

Fixed version (ground truth):
public StoreAppender(@NotNull AbstractChronicleQueue queue) throws IOException {
  super(queue);
  final long lastIndex=super.queue.lastIndex();
  this.cycle=(lastIndex == -1) ? queue.cycle() : ChronicleQueue.cycle(lastIndex);
  if (this.cycle < 0)   throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str" + cycle);
  this.store=queue.storeForCycle(this.cycle,this.epoch);
  this.index=this.store.lastSubIndex();
  final MappedBytes mappedBytes=store.mappedBytes();
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str" + mappedBytes.mappedFile().file().getAbsolutePath());
  wire=this.queue().wireType().apply(mappedBytes);
}