Program: 50372
Project: 50372
Buggy source:
private void parseCurrentLine(){
  Arrays.fill(columnStarts,0);
  Arrays.fill(columnEnds,0);
  Arrays.fill(fieldStarts,0);
  Arrays.fill(fieldEnds,0);
  columnStarts[0]=0;
  int columnIndex=0;
  int fieldIndex=0;
  lineLength=line.length();
  final int[] lineFieldIndexToColumnIndex=new int[numberOfFields];
  Arrays.fill(lineFieldIndexToColumnIndex,-1);
  previousColumnFieldIndices.clear();
  final char[] chrs=line.toCharArray();
  for (int i=0; i < lineLength; i++) {
    final char c=chrs[i];
    if (c == columnSeparatorCharacter) {
      fieldPermutation[columnIndex]=columnIndex;
      columnEnds[columnIndex]=i;
      if (columnIndex + 1 < numberOfColumns) {
        columnStarts[columnIndex + 1]=i + 1;
      }
    }
    if (c == columnSeparatorCharacter || c == fieldSeparatorCharacter || (columnIndex >= formatColumnIndex && c == formatFieldSeparatorCharacter)) {
      if (TSV) {
        fieldEnds[columnIndex]=columnEnds[columnIndex];
        fieldStarts[columnIndex]=columnStarts[columnIndex];
        fieldIndex=columnIndex;
        lineFieldIndexToColumnIndex[fieldIndex]=columnIndex;
      }
 else {
        fieldEnds[fieldIndex]=i;
        if (fieldIndex + 1 < numberOfFields) {
          fieldStarts[fieldIndex + 1]=i + 1;
        }
        previousColumnFieldIndices.add(fieldIndex);
        fieldIndex++;
      }
    }
    if (c == columnSeparatorCharacter) {
      if (TSV) {
        lineFieldIndexToColumnIndex[fieldIndex]=columnIndex;
      }
      push(columnIndex,lineFieldIndexToColumnIndex,previousColumnFieldIndices);
      columnIndex++;
    }
  }
  int numberOfFieldsOnLine=fieldIndex;
  int numberOfColumnsOnLine=columnIndex;
  columnStarts[0]=0;
  columnEnds[numberOfColumnsOnLine - (TSV ? 1 : 0)]=line.length();
  fieldStarts[0]=0;
  fieldEnds[numberOfFieldsOnLine - (TSV ? 1 : 0)]=line.length();
  previousColumnFieldIndices.add(fieldIndex);
  push(columnIndex,lineFieldIndexToColumnIndex,previousColumnFieldIndices);
  if (cacheFieldPermutation && computedFieldPermutation)   return;
  Arrays.fill(fieldPermutation,-1);
  for (  ColumnInfo c : columns) {
    c.formatIndex=0;
  }
  for (int lineFieldIndex=0; lineFieldIndex <= numberOfFieldsOnLine; lineFieldIndex++) {
    final int start=fieldStarts[lineFieldIndex];
    final int end=fieldEnds[lineFieldIndex];
    final int cIndex=lineFieldIndexToColumnIndex[lineFieldIndex];
    if (cIndex >= columnList.size()) {
      break;
    }
    final ColumnInfo column=columnList.get(cIndex);
    int colMinGlobalFieldIndex=Integer.MAX_VALUE;
    int colMaxGlobalFieldIndex=Integer.MIN_VALUE;
    final ColumnFields fields=column.fields;
    fields.rebuildList();
    for (int fi=0; fi < fields.size(); ++fi) {
      final ColumnField f=fields.get(fi);
      colMinGlobalFieldIndex=Math.min(colMinGlobalFieldIndex,f.globalFieldIndex);
      colMaxGlobalFieldIndex=Math.max(colMaxGlobalFieldIndex,f.globalFieldIndex);
    }
    final int formatColumnIndex=TSV ? -1 : formatColumn.columnIndex;
    final int startFormatColumn=TSV ? 0 : columnStarts[formatColumnIndex];
    final int endFormatColumn=TSV ? 0 : columnEnds[formatColumnIndex];
    final String[] formatTokens=split(line,formatFieldSeparatorCharacter,startFormatColumn,endFormatColumn);
    for (int fi=0; fi < fields.size(); ++fi) {
      final ColumnField f=fields.get(fi);
      if (fieldPermutation[f.globalFieldIndex] != -1) {
        continue;
      }
      if (colMaxGlobalFieldIndex == colMinGlobalFieldIndex) {
        fieldPermutation[f.globalFieldIndex]=lineFieldIndex;
        break;
      }
 else {
        int j=start;
        final String id=f.id;
        int matchLength=0;
        for (int i=0; i < id.length(); i++) {
          if (j >= end) {
            break;
          }
          final char linechar=line.charAt(j);
          if (id.charAt(i) != linechar) {
            matchLength=-1;
            break;
          }
          matchLength++;
          j++;
        }
        if (matchLength == id.length() && line.charAt(j) == '=' || (j == end && f.type == ColumnType.Flag)) {
          fieldPermutation[f.globalFieldIndex]=lineFieldIndex;
          if (f.type != ColumnType.Flag) {
            fieldStarts[lineFieldIndex]+=f.id.length() + 1;
          }
          break;
        }
 else {
          if (column.useFormat && column.formatIndex < formatTokens.length) {
            if (f.id.equals(formatTokens[column.formatIndex])) {
              fieldPermutation[f.globalFieldIndex]=lineFieldIndex;
              column.formatIndex++;
              break;
            }
          }
        }
      }
    }
  }
  computedFieldPermutation=true;
}

Fixed version (ground truth):
private void parseCurrentLine(){
  Arrays.fill(columnStarts,0);
  Arrays.fill(columnEnds,0);
  Arrays.fill(fieldStarts,0);
  Arrays.fill(fieldEnds,0);
  columnStarts[0]=0;
  int columnIndex=0;
  int fieldIndex=0;
  lineLength=line.length();
  final int[] lineFieldIndexToColumnIndex=new int[numberOfFields];
  Arrays.fill(lineFieldIndexToColumnIndex,-1);
  previousColumnFieldIndices.clear();
  final char[] chrs=line.toCharArray();
  for (int i=0; i < lineLength; i++) {
    final char c=chrs[i];
    if (c == columnSeparatorCharacter) {
      fieldPermutation[columnIndex]=columnIndex;
      columnEnds[columnIndex]=i;
      if (columnIndex + 1 < numberOfColumns) {
        columnStarts[columnIndex + 1]=i + 1;
      }
    }
    if (c == columnSeparatorCharacter || c == fieldSeparatorCharacter || (columnIndex >= formatColumnIndex && c == formatFieldSeparatorCharacter)) {
      if (TSV) {
        fieldEnds[columnIndex]=columnEnds[columnIndex];
        fieldStarts[columnIndex]=columnStarts[columnIndex];
        fieldIndex=columnIndex;
        lineFieldIndexToColumnIndex[fieldIndex]=columnIndex;
      }
 else {
        fieldEnds[fieldIndex]=i;
        if (fieldIndex + 1 < numberOfFields) {
          fieldStarts[fieldIndex + 1]=i + 1;
        }
        previousColumnFieldIndices.add(fieldIndex);
        fieldIndex++;
      }
    }
    if (c == columnSeparatorCharacter) {
      if (TSV) {
        lineFieldIndexToColumnIndex[fieldIndex]=columnIndex;
      }
      push(columnIndex,lineFieldIndexToColumnIndex,previousColumnFieldIndices);
      columnIndex++;
    }
  }
  int numberOfFieldsOnLine=Math.min(fieldIndex,fieldEnds.length - 1);
  int numberOfColumnsOnLine=Math.min(columnIndex,columnEnds.length - 1);
  columnStarts[0]=0;
  columnEnds[numberOfColumnsOnLine - (TSV ? 1 : 0)]=line.length();
  fieldStarts[0]=0;
  fieldEnds[numberOfFieldsOnLine - (TSV ? 1 : 0)]=line.length();
  previousColumnFieldIndices.add(fieldIndex);
  push(columnIndex,lineFieldIndexToColumnIndex,previousColumnFieldIndices);
  if (cacheFieldPermutation && computedFieldPermutation)   return;
  Arrays.fill(fieldPermutation,-1);
  for (  ColumnInfo c : columns) {
    c.formatIndex=0;
  }
  for (int lineFieldIndex=0; lineFieldIndex <= numberOfFieldsOnLine; lineFieldIndex++) {
    final int start=fieldStarts[lineFieldIndex];
    final int end=fieldEnds[lineFieldIndex];
    final int cIndex=lineFieldIndexToColumnIndex[lineFieldIndex];
    if (cIndex >= columnList.size()) {
      break;
    }
    final ColumnInfo column=columnList.get(cIndex);
    int colMinGlobalFieldIndex=Integer.MAX_VALUE;
    int colMaxGlobalFieldIndex=Integer.MIN_VALUE;
    final ColumnFields fields=column.fields;
    fields.rebuildList();
    for (int fi=0; fi < fields.size(); ++fi) {
      final ColumnField f=fields.get(fi);
      colMinGlobalFieldIndex=Math.min(colMinGlobalFieldIndex,f.globalFieldIndex);
      colMaxGlobalFieldIndex=Math.max(colMaxGlobalFieldIndex,f.globalFieldIndex);
    }
    final int formatColumnIndex=TSV ? -1 : formatColumn.columnIndex;
    final int startFormatColumn=TSV ? 0 : columnStarts[formatColumnIndex];
    final int endFormatColumn=TSV ? 0 : columnEnds[formatColumnIndex];
    final String[] formatTokens=split(line,formatFieldSeparatorCharacter,startFormatColumn,endFormatColumn);
    for (int fi=0; fi < fields.size(); ++fi) {
      final ColumnField f=fields.get(fi);
      if (fieldPermutation[f.globalFieldIndex] != -1) {
        continue;
      }
      if (colMaxGlobalFieldIndex == colMinGlobalFieldIndex) {
        fieldPermutation[f.globalFieldIndex]=lineFieldIndex;
        break;
      }
 else {
        int j=start;
        final String id=f.id;
        int matchLength=0;
        for (int i=0; i < id.length(); i++) {
          if (j >= end) {
            break;
          }
          final char linechar=line.charAt(j);
          if (id.charAt(i) != linechar) {
            matchLength=-1;
            break;
          }
          matchLength++;
          j++;
        }
        if (matchLength == id.length() && line.charAt(j) == '=' || (j == end && f.type == ColumnType.Flag)) {
          fieldPermutation[f.globalFieldIndex]=lineFieldIndex;
          if (f.type != ColumnType.Flag) {
            fieldStarts[lineFieldIndex]+=f.id.length() + 1;
          }
          break;
        }
 else {
          if (column.useFormat && column.formatIndex < formatTokens.length) {
            if (f.id.equals(formatTokens[column.formatIndex])) {
              fieldPermutation[f.globalFieldIndex]=lineFieldIndex;
              column.formatIndex++;
              break;
            }
          }
        }
      }
    }
  }
  computedFieldPermutation=true;
}