Program: 162811
Project: 162811
Buggy source:
@Override public void recoverSegments(){
  Logger log=lh.LOG;
  VanillaChronicleHash<?,?,?,?> h=hh.h();
  for (int segmentIndex=0; segmentIndex < h.actualSegments; segmentIndex++) {
    s.initSegmentIndex(segmentIndex);
    resetSegmentLock();
    zeroOutFirstSegmentTierCountersArea();
    tierRecovery.recoverTier(segmentIndex);
  }
  VanillaGlobalMutableState globalMutableState=h.globalMutableState();
  long storedExtraTiersInUse=globalMutableState.getExtraTiersInUse();
  long allocatedExtraTiers=globalMutableState.getAllocatedExtraTierBulks() * h.tiersInBulk;
  long expectedExtraTiersInUse=Math.max(0,Math.min(storedExtraTiersInUse,allocatedExtraTiers));
  long actualExtraTiersInUse=0;
  long firstFreeExtraTierIndex=-1;
  for (long extraTierIndex=0; extraTierIndex < expectedExtraTiersInUse; extraTierIndex++) {
    long tierIndex=h.extraTierIndexToTierIndex(extraTierIndex);
    s.initSegmentTier(0,tierIndex);
    int segmentIndex=tierRecovery.recoverTier(-1);
    if (segmentIndex > 0) {
      long tierCountersAreaAddr=s.tierCountersAreaAddr();
      int storedSegmentIndex=TierCountersArea.segmentIndex(tierCountersAreaAddr);
      if (storedSegmentIndex != segmentIndex) {
        log.error("String_Node_Str" + "String_Node_Str",tierIndex,storedSegmentIndex,segmentIndex);
        TierCountersArea.segmentIndex(tierCountersAreaAddr,segmentIndex);
      }
      s.nextTierIndex(0);
      s.initSegmentIndex(segmentIndex);
      s.goToLastTier();
      s.nextTierIndex(tierIndex);
      TierCountersArea.prevTierIndex(tierCountersAreaAddr,s.tierIndex);
      TierCountersArea.tier(tierCountersAreaAddr,s.tier + 1);
      actualExtraTiersInUse=extraTierIndex + 1;
    }
 else {
      firstFreeExtraTierIndex=extraTierIndex;
      break;
    }
  }
  if (storedExtraTiersInUse != actualExtraTiersInUse) {
    log.error("String_Node_Str" + "String_Node_Str",storedExtraTiersInUse,actualExtraTiersInUse);
    globalMutableState.setExtraTiersInUse(actualExtraTiersInUse);
  }
  long firstFreeTierIndex;
  if (firstFreeExtraTierIndex == -1) {
    if (allocatedExtraTiers > expectedExtraTiersInUse) {
      firstFreeTierIndex=h.extraTierIndexToTierIndex(expectedExtraTiersInUse);
    }
 else {
      firstFreeTierIndex=0;
    }
  }
 else {
    firstFreeTierIndex=h.extraTierIndexToTierIndex(firstFreeExtraTierIndex);
  }
  if (firstFreeTierIndex > 0) {
    long lastTierIndex=h.extraTierIndexToTierIndex(allocatedExtraTiers - 1);
    h.linkAndZeroOutFreeTiers(firstFreeTierIndex,lastTierIndex);
  }
  long storedFirstFreeTierIndex=globalMutableState.getFirstFreeTierIndex();
  if (storedFirstFreeTierIndex != firstFreeTierIndex) {
    log.error("String_Node_Str" + "String_Node_Str",storedFirstFreeTierIndex,firstFreeTierIndex);
  }
  removeDuplicatesInSegments();
}

Fixed version (ground truth):
@Override public void recoverSegments(){
  Logger log=lh.LOG;
  VanillaChronicleHash<?,?,?,?> h=hh.h();
  for (int segmentIndex=0; segmentIndex < h.actualSegments; segmentIndex++) {
    s.initSegmentIndex(segmentIndex);
    resetSegmentLock();
    zeroOutFirstSegmentTierCountersArea();
    tierRecovery.recoverTier(segmentIndex);
  }
  VanillaGlobalMutableState globalMutableState=h.globalMutableState();
  long storedExtraTiersInUse=globalMutableState.getExtraTiersInUse();
  long allocatedExtraTiers=globalMutableState.getAllocatedExtraTierBulks() * h.tiersInBulk;
  long expectedExtraTiersInUse=Math.max(0,Math.min(storedExtraTiersInUse,allocatedExtraTiers));
  long actualExtraTiersInUse=0;
  long firstFreeExtraTierIndex=-1;
  for (long extraTierIndex=0; extraTierIndex < expectedExtraTiersInUse; extraTierIndex++) {
    long tierIndex=h.extraTierIndexToTierIndex(extraTierIndex);
    s.initSegmentTier(0,tierIndex);
    int segmentIndex=tierRecovery.recoverTier(-1);
    if (segmentIndex >= 0) {
      long tierCountersAreaAddr=s.tierCountersAreaAddr();
      int storedSegmentIndex=TierCountersArea.segmentIndex(tierCountersAreaAddr);
      if (storedSegmentIndex != segmentIndex) {
        log.error("String_Node_Str" + "String_Node_Str",tierIndex,storedSegmentIndex,segmentIndex);
        TierCountersArea.segmentIndex(tierCountersAreaAddr,segmentIndex);
      }
      s.nextTierIndex(0);
      s.initSegmentIndex(segmentIndex);
      s.goToLastTier();
      s.nextTierIndex(tierIndex);
      TierCountersArea.prevTierIndex(tierCountersAreaAddr,s.tierIndex);
      TierCountersArea.tier(tierCountersAreaAddr,s.tier + 1);
      actualExtraTiersInUse=extraTierIndex + 1;
    }
 else {
      firstFreeExtraTierIndex=extraTierIndex;
      break;
    }
  }
  if (storedExtraTiersInUse != actualExtraTiersInUse) {
    log.error("String_Node_Str" + "String_Node_Str",storedExtraTiersInUse,actualExtraTiersInUse);
    globalMutableState.setExtraTiersInUse(actualExtraTiersInUse);
  }
  long firstFreeTierIndex;
  if (firstFreeExtraTierIndex == -1) {
    if (allocatedExtraTiers > expectedExtraTiersInUse) {
      firstFreeTierIndex=h.extraTierIndexToTierIndex(expectedExtraTiersInUse);
    }
 else {
      firstFreeTierIndex=0;
    }
  }
 else {
    firstFreeTierIndex=h.extraTierIndexToTierIndex(firstFreeExtraTierIndex);
  }
  if (firstFreeTierIndex > 0) {
    long lastTierIndex=h.extraTierIndexToTierIndex(allocatedExtraTiers - 1);
    h.linkAndZeroOutFreeTiers(firstFreeTierIndex,lastTierIndex);
  }
  long storedFirstFreeTierIndex=globalMutableState.getFirstFreeTierIndex();
  if (storedFirstFreeTierIndex != firstFreeTierIndex) {
    log.error("String_Node_Str" + "String_Node_Str",storedFirstFreeTierIndex,firstFreeTierIndex);
  }
  removeDuplicatesInSegments();
}