Program: 112140
Project: 112140
Buggy source:
/** 
 * @param root the root of the schema
 * @param leaves the leaves of the schema
 * @param validating
 * @param columns2
 */
public RecordReaderImplementation(MessageColumnIO root,RecordMaterializer<T> recordMaterializer,boolean validating,ColumnsStore columnStore){
  this.recordMaterializer=recordMaterializer;
  this.recordConsumer=validator(wrap(recordMaterializer),validating,root.getType());
  PrimitiveColumnIO[] leaves=root.getLeaves().toArray(new PrimitiveColumnIO[root.getLeaves().size()]);
  ColumnReader[] columns=new ColumnReader[leaves.length];
  int[][] nextReader=new int[leaves.length][];
  int[][] nextLevel=new int[leaves.length][];
  int[] firsts=new int[256];
  for (int i=0; i < leaves.length; i++) {
    PrimitiveColumnIO primitiveColumnIO=leaves[i];
    columns[i]=columnStore.getColumnReader(primitiveColumnIO.getColumnDescriptor());
    int repetitionLevel=primitiveColumnIO.getRepetitionLevel();
    nextReader[i]=new int[repetitionLevel + 1];
    nextLevel[i]=new int[repetitionLevel + 1];
    for (int r=0; r <= repetitionLevel; ++r) {
      if (primitiveColumnIO.isFirst(r)) {
        firsts[r]=i;
      }
      int next;
      if (r == 0) {
        next=i + 1;
      }
 else       if (primitiveColumnIO.isLast(r)) {
        next=firsts[r];
      }
 else {
        next=i + 1;
      }
      if (next == leaves.length) {
        nextLevel[i][r]=0;
      }
 else       if (primitiveColumnIO.isLast(r)) {
        ColumnIO parent=primitiveColumnIO.getParent(r);
        nextLevel[i][r]=parent.getFieldPath().length - 1;
      }
 else {
        nextLevel[i][r]=getCommonParentLevel(primitiveColumnIO.getFieldPath(),leaves[next].getFieldPath());
      }
      if (nextLevel[i][r] > leaves[i].getFieldPath().length - 1) {
        throw new RuntimeException(Arrays.toString(leaves[i].getFieldPath()) + "String_Node_Str" + r+ "String_Node_Str"+ nextLevel[i][r]);
      }
      nextReader[i][r]=next;
    }
  }
  states=new State[leaves.length];
  for (int i=0; i < leaves.length; i++) {
    states[i]=new State(i,leaves[i],columns[i],nextLevel[i]);
    int[] definitionLevelToDepth=new int[states[i].primitiveColumnIO.getDefinitionLevel() + 1];
    int depth=0;
    for (int d=0; d < definitionLevelToDepth.length; ++d) {
      while (depth < (states[i].fieldPath.length - 1) && d > states[i].primitiveColumnIO.getPath()[depth].getDefinitionLevel()) {
        ++depth;
      }
      definitionLevelToDepth[d]=depth - 1;
    }
    states[i].definitionLevelToDepth=definitionLevelToDepth;
  }
  for (int i=0; i < leaves.length; i++) {
    State state=states[i];
    int[] nextStateIds=nextReader[i];
    state.nextState=new State[nextStateIds.length];
    for (int j=0; j < nextStateIds.length; j++) {
      state.nextState[j]=nextStateIds[j] == states.length ? null : states[nextStateIds[j]];
    }
  }
  for (int i=0; i < states.length; i++) {
    State state=states[i];
    final Map<Case,Case> cases=new HashMap<Case,Case>();
    int nextCaseID=0;
    Case[][][] caseLookup=new Case[state.fieldPath.length][][];
    for (int currentLevel=0; currentLevel < state.fieldPath.length; ++currentLevel) {
      caseLookup[currentLevel]=new Case[state.maxDefinitionLevel + 1][];
      for (int d=0; d <= state.maxDefinitionLevel; ++d) {
        caseLookup[currentLevel][d]=new Case[state.maxRepetitionLevel + 1];
        for (int nextR=0; nextR <= state.maxRepetitionLevel; ++nextR) {
          int caseStartLevel=currentLevel;
          int caseDepth=Math.max(state.getDepth(d),caseStartLevel - 1);
          int caseNextLevel=Math.min(state.nextLevel[nextR],caseDepth + 1);
          Case currentCase=new Case(caseStartLevel,caseDepth,caseNextLevel);
          if (!cases.containsKey(currentCase)) {
            currentCase.setID(++nextCaseID);
            cases.put(currentCase,currentCase);
          }
 else {
            currentCase=cases.get(currentCase);
          }
          caseLookup[currentLevel][d][nextR]=currentCase;
        }
      }
    }
    state.caseLookup=caseLookup;
    state.cases=cases.values();
  }
}

Fixed version (ground truth):
/** 
 * @param root the root of the schema
 * @param leaves the leaves of the schema
 * @param validating
 * @param columns2
 */
public RecordReaderImplementation(MessageColumnIO root,RecordMaterializer<T> recordMaterializer,boolean validating,ColumnsStore columnStore){
  this.recordMaterializer=recordMaterializer;
  this.recordConsumer=validator(wrap(recordMaterializer),validating,root.getType());
  PrimitiveColumnIO[] leaves=root.getLeaves().toArray(new PrimitiveColumnIO[root.getLeaves().size()]);
  ColumnReader[] columns=new ColumnReader[leaves.length];
  int[][] nextReader=new int[leaves.length][];
  int[][] nextLevel=new int[leaves.length][];
  int[] firsts=new int[256];
  for (int i=0; i < leaves.length; i++) {
    PrimitiveColumnIO primitiveColumnIO=leaves[i];
    columns[i]=columnStore.getColumnReader(primitiveColumnIO.getColumnDescriptor());
    int repetitionLevel=primitiveColumnIO.getRepetitionLevel();
    nextReader[i]=new int[repetitionLevel + 1];
    nextLevel[i]=new int[repetitionLevel + 1];
    for (int r=0; r <= repetitionLevel; ++r) {
      if (primitiveColumnIO.isFirst(r)) {
        firsts[r]=i;
      }
      int next;
      if (r == 0) {
        next=i + 1;
      }
 else       if (primitiveColumnIO.isLast(r)) {
        next=firsts[r];
      }
 else {
        next=i + 1;
      }
      if (next == leaves.length) {
        nextLevel[i][r]=0;
      }
 else       if (primitiveColumnIO.isLast(r)) {
        ColumnIO parent=primitiveColumnIO.getParent(r);
        nextLevel[i][r]=parent.getFieldPath().length - 1;
      }
 else {
        nextLevel[i][r]=getCommonParentLevel(primitiveColumnIO.getFieldPath(),leaves[next].getFieldPath());
      }
      if (nextLevel[i][r] > leaves[i].getFieldPath().length - 1) {
        throw new RuntimeException(Arrays.toString(leaves[i].getFieldPath()) + "String_Node_Str" + r+ "String_Node_Str"+ nextLevel[i][r]);
      }
      nextReader[i][r]=next;
    }
  }
  states=new State[leaves.length];
  for (int i=0; i < leaves.length; i++) {
    states[i]=new State(i,leaves[i],columns[i],nextLevel[i]);
    int[] definitionLevelToDepth=new int[states[i].primitiveColumnIO.getDefinitionLevel() + 1];
    int depth=0;
    for (int d=0; d < definitionLevelToDepth.length; ++d) {
      while (depth < (states[i].fieldPath.length - 1) && d > states[i].primitiveColumnIO.getPath()[depth].getDefinitionLevel()) {
        ++depth;
      }
      definitionLevelToDepth[d]=depth - 1;
    }
    states[i].definitionLevelToDepth=definitionLevelToDepth;
  }
  for (int i=0; i < leaves.length; i++) {
    State state=states[i];
    int[] nextStateIds=nextReader[i];
    state.nextState=new State[nextStateIds.length];
    for (int j=0; j < nextStateIds.length; j++) {
      state.nextState[j]=nextStateIds[j] == states.length ? null : states[nextStateIds[j]];
    }
  }
  for (int i=0; i < states.length; i++) {
    State state=states[i];
    final Map<Case,Case> cases=new HashMap<Case,Case>();
    int nextCaseID=0;
    Case[][][] caseLookup=new Case[state.fieldPath.length][][];
    for (int currentLevel=0; currentLevel < state.fieldPath.length; ++currentLevel) {
      caseLookup[currentLevel]=new Case[state.maxDefinitionLevel + 1][];
      for (int d=0; d <= state.maxDefinitionLevel; ++d) {
        caseLookup[currentLevel][d]=new Case[state.maxRepetitionLevel + 1];
        for (int nextR=0; nextR <= state.maxRepetitionLevel; ++nextR) {
          int caseStartLevel=currentLevel;
          int caseDepth=Math.max(state.getDepth(d),caseStartLevel - 1);
          int caseNextLevel=Math.min(state.nextLevel[nextR],caseDepth + 1);
          Case currentCase=new Case(caseStartLevel,caseDepth,caseNextLevel);
          if (!cases.containsKey(currentCase)) {
            currentCase.setID(nextCaseID++);
            cases.put(currentCase,currentCase);
          }
 else {
            currentCase=cases.get(currentCase);
          }
          caseLookup[currentLevel][d][nextR]=currentCase;
        }
      }
    }
    state.caseLookup=caseLookup;
    state.cases=new ArrayList<Case>(cases.values());
    Collections.sort(state.cases,new Comparator<Case>(){
      @Override public int compare(      Case o1,      Case o2){
        return o1.id - o2.id;
      }
    }
);
  }
}