Program: 8166
Project: 8166
Buggy source:
@Override public DequeueResult dequeue(QueueConsumer consumer,QueueConfig config,ReadPointer readPointer){
  if (TRACE)   log("String_Node_Str" + dequeueReturns.get() + "String_Node_Str"+ consumer+ "String_Node_Str"+ config+ "String_Node_Str"+ readPointer+ "String_Node_Str");
  ImmutablePair<ReadPointer,Long> dirty=dirtyPointer();
  GroupState groupState=null;
  byte[] groupRow=makeRow(GLOBAL_GROUPS_HEADER,consumer.getGroupId());
  while (true) {
    byte[] existingValue=this.table.get(groupRow,GROUP_STATE,dirty.getFirst());
    if (existingValue == null || existingValue.length == 0) {
      log("String_Node_Str");
      groupState=new GroupState(consumer.getGroupSize(),new EntryPointer(1,1),config.isSingleEntry() ? ExecutionMode.SINGLE_ENTRY : ExecutionMode.MULTI_ENTRY);
      if (this.table.compareAndSwap(groupRow,GROUP_STATE,existingValue,groupState.getBytes(),dirty.getFirst(),dirty.getSecond())) {
        break;
      }
 else {
        continue;
      }
    }
 else {
      groupState=GroupState.fromBytes(existingValue);
      if (TRACE)       log("String_Node_Str" + groupState);
      if (groupState.getGroupSize() == consumer.getGroupSize() && groupState.getMode() == ExecutionMode.fromQueueConfig(config)) {
        break;
      }
      if (!groupIsEmpty(groupState,consumer.getGroupId(),dirty.getFirst())) {
        if (TRACE)         log("String_Node_Str");
        return new DequeueResult(DequeueStatus.FAILURE,"String_Node_Str");
      }
      groupState=new GroupState(consumer.getGroupSize(),groupState.getHead(),ExecutionMode.fromQueueConfig(config));
      if (this.table.compareAndSwap(groupRow,GROUP_STATE,existingValue,groupState.getBytes(),dirty.getFirst(),dirty.getSecond())) {
        log("String_Node_Str");
        break;
      }
 else {
        log("String_Node_Str");
        continue;
      }
    }
  }
  EntryMeta entryMeta=null;
  EntryGroupMeta entryGroupMeta=null;
  EntryPointer entryPointer=groupState.getHead();
  while (entryPointer != null) {
    byte[] shardRow=makeRow(GLOBAL_DATA_HEADER,entryPointer.getShardId());
    byte[] entryMetaColumn=makeColumn(entryPointer.getEntryId(),ENTRY_META);
    ImmutablePair<byte[],Long> entryMetaDataAndStamp=this.table.getWithVersion(shardRow,entryMetaColumn,dirty.getFirst());
    if (entryMetaDataAndStamp == null) {
      log("String_Node_Str" + entryPointer + "String_Node_Str"+ "String_Node_Str"+ dirty.getFirst());
      return new DequeueResult(DequeueStatus.EMPTY);
    }
    if (!readPointer.isVisible(entryMetaDataAndStamp.getSecond())) {
      log("String_Node_Str" + entryPointer + "String_Node_Str");
      quickWait();
      return new DequeueResult(DequeueStatus.RETRY);
    }
    entryMeta=EntryMeta.fromBytes(entryMetaDataAndStamp.getFirst());
    if (TRACE)     log("String_Node_Str" + entryMeta.toString());
    if (entryMeta.isInvalid()) {
      if (TRACE)       log("String_Node_Str" + entryPointer);
      EntryPointer nextEntryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
      if (entryPointer.equals(groupState.getHead())) {
        GroupState newGroupState=new GroupState(groupState.getGroupSize(),nextEntryPointer,groupState.getMode());
        if (this.table.compareAndSwap(groupRow,GROUP_STATE,groupState.getBytes(),newGroupState.getBytes(),dirty.getFirst(),dirty.getSecond())) {
          groupState=newGroupState;
        }
 else {
          groupState=GroupState.fromBytes(this.table.get(groupRow,GROUP_STATE,dirty.getFirst()));
        }
      }
      entryPointer=nextEntryPointer;
      continue;
    }
    if (entryMeta.iEndOfShard()) {
      if (TRACE)       log("String_Node_Str" + entryPointer.getShardId() + "String_Node_Str"+ (entryPointer.getShardId() + 1));
      EntryPointer nextEntryPointer=new EntryPointer(entryPointer.getEntryId(),entryPointer.getShardId() + 1);
      if (entryPointer.equals(groupState.getHead())) {
        GroupState newGroupState=new GroupState(groupState.getGroupSize(),nextEntryPointer,groupState.getMode());
        if (this.table.compareAndSwap(groupRow,GROUP_STATE,groupState.getBytes(),newGroupState.getBytes(),dirty.getFirst(),dirty.getSecond())) {
          groupState=newGroupState;
        }
 else {
          groupState=GroupState.fromBytes(this.table.get(groupRow,GROUP_STATE,dirty.getFirst()));
        }
      }
      entryPointer=nextEntryPointer;
      continue;
    }
    assert(entryMeta.isValid());
    byte[] entryGroupMetaColumn=makeColumn(entryPointer.getEntryId(),ENTRY_GROUP_META,consumer.getGroupId());
    byte[] entryGroupMetaData=this.table.get(shardRow,entryGroupMetaColumn,dirty.getFirst());
    if (entryGroupMetaData == null || entryGroupMetaData.length == 0) {
      if (TRACE)       log("String_Node_Str" + entryPointer.getEntryId());
      entryGroupMetaData=null;
    }
 else {
      entryGroupMeta=EntryGroupMeta.fromBytes(entryGroupMetaData);
      if (TRACE)       log("String_Node_Str" + entryPointer.getEntryId() + "String_Node_Str"+ entryGroupMeta.toString());
      if (entryGroupMeta.isAckedOrSemiAcked()) {
        if (TRACE)         log("String_Node_Str");
        EntryPointer nextEntryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
        if (entryPointer.equals(groupState.getHead()) && safeToMoveHead(entryGroupMeta)) {
          GroupState newGroupState=new GroupState(groupState.getGroupSize(),nextEntryPointer,groupState.getMode());
          if (this.table.compareAndSwap(groupRow,GROUP_STATE,groupState.getBytes(),newGroupState.getBytes(),dirty.getFirst(),dirty.getSecond())) {
            groupState=newGroupState;
          }
 else {
            groupState=GroupState.fromBytes(this.table.get(groupRow,GROUP_STATE,dirty.getFirst()));
          }
        }
        entryPointer=nextEntryPointer;
        continue;
      }
      if (entryGroupMeta.isDequeued()) {
        if (TRACE)         log("String_Node_Str");
        if (config.isSingleEntry() && entryGroupMeta.getInstanceId() == consumer.getInstanceId()) {
          if (TRACE)           log("String_Node_Str");
          EntryGroupMeta newEntryGroupMeta=new EntryGroupMeta(EntryGroupState.DEQUEUED,now(),consumer.getInstanceId());
          if (this.table.compareAndSwap(shardRow,entryGroupMetaColumn,entryGroupMetaData,newEntryGroupMeta.getBytes(),dirty.getFirst(),dirty.getSecond())) {
            dequeueReturns.incrementAndGet();
            return new DequeueResult(DequeueStatus.SUCCESS,entryPointer,this.table.get(shardRow,makeColumn(entryPointer.getEntryId(),ENTRY_DATA),dirty.getFirst()));
          }
 else {
            entryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
            continue;
          }
        }
        if (entryGroupMeta.getTimestamp() + this.maxAgeBeforeExpirationInMillis >= now()) {
          log("String_Node_Str" + entryGroupMeta.getTimestamp() + "String_Node_Str"+ this.maxAgeBeforeExpirationInMillis+ "String_Node_Str"+ now());
          entryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
          continue;
        }
      }
    }
    if (TRACE)     log("String_Node_Str");
    byte[] data=this.table.get(shardRow,makeColumn(entryPointer.getEntryId(),ENTRY_DATA),dirty.getFirst());
    if (!config.getPartitioner().shouldEmit(consumer,entryPointer.getEntryId(),data)) {
      entryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
      continue;
    }
    EntryGroupMeta newEntryGroupMeta=new EntryGroupMeta(EntryGroupState.DEQUEUED,now(),consumer.getInstanceId());
    if (this.table.compareAndSwap(shardRow,entryGroupMetaColumn,entryGroupMetaData,newEntryGroupMeta.getBytes(),dirty.getFirst(),dirty.getSecond())) {
      dequeueReturns.incrementAndGet();
      if (TRACE)       log("String_Node_Str" + entryPointer + "String_Node_Str"+ newEntryGroupMeta);
      return new DequeueResult(DequeueStatus.SUCCESS,entryPointer,data);
    }
 else {
      if (TRACE)       log("String_Node_Str" + entryPointer);
      entryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
      continue;
    }
  }
  throw new RuntimeException("String_Node_Str");
}

Fixed version (ground truth):
@Override public DequeueResult dequeue(QueueConsumer consumer,QueueConfig config,ReadPointer readPointer){
  if (TRACE)   log("String_Node_Str" + dequeueReturns.get() + "String_Node_Str"+ consumer+ "String_Node_Str"+ config+ "String_Node_Str"+ readPointer+ "String_Node_Str");
  ImmutablePair<ReadPointer,Long> dirty=dirtyPointer();
  GroupState groupState=null;
  byte[] groupRow=makeRow(GLOBAL_GROUPS_HEADER,consumer.getGroupId());
  while (true) {
    byte[] existingValue=this.table.get(groupRow,GROUP_STATE,dirty.getFirst());
    if (existingValue == null || existingValue.length == 0) {
      log("String_Node_Str");
      groupState=new GroupState(consumer.getGroupSize(),new EntryPointer(1,1),config.isSingleEntry() ? ExecutionMode.SINGLE_ENTRY : ExecutionMode.MULTI_ENTRY);
      if (this.table.compareAndSwap(groupRow,GROUP_STATE,existingValue,groupState.getBytes(),dirty.getFirst(),dirty.getSecond())) {
        break;
      }
 else {
        continue;
      }
    }
 else {
      groupState=GroupState.fromBytes(existingValue);
      if (TRACE)       log("String_Node_Str" + groupState);
      if (groupState.getGroupSize() == consumer.getGroupSize() && groupState.getMode() == ExecutionMode.fromQueueConfig(config)) {
        break;
      }
      if (!groupIsEmpty(groupState,consumer.getGroupId(),dirty.getFirst())) {
        if (TRACE)         log("String_Node_Str");
        return new DequeueResult(DequeueStatus.FAILURE,"String_Node_Str");
      }
      groupState=new GroupState(consumer.getGroupSize(),groupState.getHead(),ExecutionMode.fromQueueConfig(config));
      if (this.table.compareAndSwap(groupRow,GROUP_STATE,existingValue,groupState.getBytes(),dirty.getFirst(),dirty.getSecond())) {
        log("String_Node_Str");
        break;
      }
 else {
        log("String_Node_Str");
        continue;
      }
    }
  }
  EntryMeta entryMeta=null;
  EntryGroupMeta entryGroupMeta=null;
  EntryPointer entryPointer=groupState.getHead();
  while (entryPointer != null) {
    byte[] shardRow=makeRow(GLOBAL_DATA_HEADER,entryPointer.getShardId());
    byte[] entryMetaColumn=makeColumn(entryPointer.getEntryId(),ENTRY_META);
    ImmutablePair<byte[],Long> entryMetaDataAndStamp=this.table.getWithVersion(shardRow,entryMetaColumn,dirty.getFirst());
    if (entryMetaDataAndStamp == null) {
      log("String_Node_Str" + entryPointer + "String_Node_Str"+ "String_Node_Str"+ dirty.getFirst());
      return new DequeueResult(DequeueStatus.EMPTY);
    }
    if (!readPointer.isVisible(entryMetaDataAndStamp.getSecond())) {
      log("String_Node_Str" + entryPointer + "String_Node_Str");
      quickWait();
      return new DequeueResult(DequeueStatus.RETRY);
    }
    entryMeta=EntryMeta.fromBytes(entryMetaDataAndStamp.getFirst());
    if (TRACE)     log("String_Node_Str" + entryMeta.toString());
    if (entryMeta.isInvalid()) {
      if (TRACE)       log("String_Node_Str" + entryPointer);
      EntryPointer nextEntryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
      if (entryPointer.equals(groupState.getHead())) {
        GroupState newGroupState=new GroupState(groupState.getGroupSize(),nextEntryPointer,groupState.getMode());
        if (this.table.compareAndSwap(groupRow,GROUP_STATE,groupState.getBytes(),newGroupState.getBytes(),dirty.getFirst(),dirty.getSecond())) {
          groupState=newGroupState;
        }
 else {
          groupState=GroupState.fromBytes(this.table.get(groupRow,GROUP_STATE,dirty.getFirst()));
        }
      }
      entryPointer=nextEntryPointer;
      continue;
    }
    if (entryMeta.iEndOfShard()) {
      if (TRACE)       log("String_Node_Str" + entryPointer.getShardId() + "String_Node_Str"+ (entryPointer.getShardId() + 1));
      EntryPointer nextEntryPointer=new EntryPointer(entryPointer.getEntryId(),entryPointer.getShardId() + 1);
      if (entryPointer.equals(groupState.getHead())) {
        GroupState newGroupState=new GroupState(groupState.getGroupSize(),nextEntryPointer,groupState.getMode());
        if (this.table.compareAndSwap(groupRow,GROUP_STATE,groupState.getBytes(),newGroupState.getBytes(),dirty.getFirst(),dirty.getSecond())) {
          groupState=newGroupState;
        }
 else {
          groupState=GroupState.fromBytes(this.table.get(groupRow,GROUP_STATE,dirty.getFirst()));
        }
      }
      entryPointer=nextEntryPointer;
      continue;
    }
    assert(entryMeta.isValid());
    byte[] entryGroupMetaColumn=makeColumn(entryPointer.getEntryId(),ENTRY_GROUP_META,consumer.getGroupId());
    byte[] entryGroupMetaData=this.table.get(shardRow,entryGroupMetaColumn,dirty.getFirst());
    if (entryGroupMetaData == null || entryGroupMetaData.length == 0) {
      if (TRACE)       log("String_Node_Str" + entryPointer.getEntryId());
      entryGroupMetaData=null;
    }
 else {
      entryGroupMeta=EntryGroupMeta.fromBytes(entryGroupMetaData);
      if (TRACE)       log("String_Node_Str" + entryPointer.getEntryId() + "String_Node_Str"+ entryGroupMeta.toString());
      if (entryGroupMeta.isAckedOrSemiAcked()) {
        if (TRACE)         log("String_Node_Str");
        EntryPointer nextEntryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
        if (entryPointer.equals(groupState.getHead()) && safeToMoveHead(entryGroupMeta)) {
          GroupState newGroupState=new GroupState(groupState.getGroupSize(),nextEntryPointer,groupState.getMode());
          if (this.table.compareAndSwap(groupRow,GROUP_STATE,groupState.getBytes(),newGroupState.getBytes(),dirty.getFirst(),dirty.getSecond())) {
            groupState=newGroupState;
          }
 else {
            groupState=GroupState.fromBytes(this.table.get(groupRow,GROUP_STATE,dirty.getFirst()));
          }
        }
        entryPointer=nextEntryPointer;
        continue;
      }
      if (entryGroupMeta.isDequeued()) {
        if (TRACE)         log("String_Node_Str");
        if (config.isSingleEntry() && entryGroupMeta.getInstanceId() == consumer.getInstanceId()) {
          if (TRACE)           log("String_Node_Str");
          EntryGroupMeta newEntryGroupMeta=new EntryGroupMeta(EntryGroupState.DEQUEUED,now(),consumer.getInstanceId());
          if (this.table.compareAndSwap(shardRow,entryGroupMetaColumn,entryGroupMetaData,newEntryGroupMeta.getBytes(),dirty.getFirst(),dirty.getSecond())) {
            dequeueReturns.incrementAndGet();
            return new DequeueResult(DequeueStatus.SUCCESS,entryPointer,this.table.get(shardRow,makeColumn(entryPointer.getEntryId(),ENTRY_DATA),dirty.getFirst()));
          }
 else {
            entryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
            continue;
          }
        }
        if (entryGroupMeta.getTimestamp() + this.maxAgeBeforeExpirationInMillis >= now()) {
          log("String_Node_Str" + entryGroupMeta.getTimestamp() + "String_Node_Str"+ this.maxAgeBeforeExpirationInMillis+ "String_Node_Str"+ now());
          entryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
          continue;
        }
      }
    }
    if (TRACE)     log("String_Node_Str");
    byte[] data=this.table.get(shardRow,makeColumn(entryPointer.getEntryId(),ENTRY_DATA),dirty.getFirst());
    assert(data != null);
    if (!config.getPartitioner().shouldEmit(consumer,entryPointer.getEntryId(),data)) {
      entryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
      continue;
    }
    EntryGroupMeta newEntryGroupMeta=new EntryGroupMeta(EntryGroupState.DEQUEUED,now(),consumer.getInstanceId());
    if (this.table.compareAndSwap(shardRow,entryGroupMetaColumn,entryGroupMetaData,newEntryGroupMeta.getBytes(),dirty.getFirst(),dirty.getSecond())) {
      dequeueReturns.incrementAndGet();
      if (TRACE)       log("String_Node_Str" + entryPointer + "String_Node_Str"+ newEntryGroupMeta);
      return new DequeueResult(DequeueStatus.SUCCESS,entryPointer,data);
    }
 else {
      if (TRACE)       log("String_Node_Str" + entryPointer);
      entryPointer=new EntryPointer(entryPointer.getEntryId() + 1,entryPointer.getShardId());
      continue;
    }
  }
  throw new RuntimeException("String_Node_Str");
}