Program: 50347
Project: 50347
Buggy source:
private void applyCigar(){
  if (debug && LOG.isDebugEnabled()) {
    LOG.debug(String.format("String_Node_Str",cigar));
  }
  int posInReads=0;
  numInsertions=0;
  numDeletions=0;
  numMisMatches=0;
  Matcher matcher=CIGAR_REGEX.matcher(cigar);
  while (matcher.find()) {
    int length=Integer.parseInt(matcher.group(1));
    char op=matcher.group(2).charAt(0);
switch (op) {
case 'S':
      for (int i=0; i < length; i++) {
        ref.append('-');
        query.append('-');
        qual.append(minQualValue);
      }
    posInReads+=length;
  break;
case 'M':
query.append(sourceQuery.substring(posInReads,posInReads + length));
if (sourceQual.length() != 0) {
qual.append(sourceQual.substring(posInReads,posInReads + length));
}
ref.append(sourceQuery.substring(posInReads,posInReads + length));
posInReads+=length;
break;
case 'I':
query.append(sourceQuery.substring(posInReads,posInReads + length));
if (sourceQual.length() != 0) {
qual.append(sourceQual.substring(posInReads,posInReads + length));
}
for (int i=0; i < length; i++) {
ref.append('-');
}
numInsertions+=length;
posInReads+=length;
break;
case 'D':
for (int i=0; i < length; i++) {
query.append('-');
if (sourceQual.length() != 0) {
qual.append(minQualValue);
}
ref.append('?');
}
numDeletions+=length;
break;
}
}
for (int i=0; i < query.length(); i++) {
if (query.charAt(i) == '-' && ref.charAt(i) == '-') {
numLeftClipped++;
}
 else {
break;
}
}
for (int i=query.length() - 1; i >= 0; i--) {
if (query.charAt(i) == '-' && ref.charAt(i) == '-') {
numRightClipped++;
}
 else {
break;
}
}
}

Fixed version (ground truth):
private void applyCigar(){
  if (debug && LOG.isDebugEnabled()) {
    LOG.debug(String.format("String_Node_Str",cigar));
  }
  int posInReads=0;
  numInsertions=0;
  numDeletions=0;
  numMisMatches=0;
  Matcher matcher=CIGAR_REGEX.matcher(cigar);
  while (matcher.find()) {
    int length=Integer.parseInt(matcher.group(1));
    char op=matcher.group(2).charAt(0);
switch (op) {
case 'S':
      for (int i=0; i < length; i++) {
        ref.append('-');
        query.append('-');
        qual.append((char)minQualValue);
      }
    posInReads+=length;
  break;
case 'M':
query.append(sourceQuery.substring(posInReads,posInReads + length));
if (sourceQual.length() != 0) {
qual.append(sourceQual.substring(posInReads,posInReads + length));
}
ref.append(sourceQuery.substring(posInReads,posInReads + length));
posInReads+=length;
break;
case 'I':
query.append(sourceQuery.substring(posInReads,posInReads + length));
if (sourceQual.length() != 0) {
qual.append(sourceQual.substring(posInReads,posInReads + length));
}
for (int i=0; i < length; i++) {
ref.append('-');
}
numInsertions+=length;
posInReads+=length;
break;
case 'D':
for (int i=0; i < length; i++) {
query.append('-');
if (sourceQual.length() != 0) {
qual.append((char)minQualValue);
}
ref.append('?');
}
numDeletions+=length;
break;
}
}
for (int i=0; i < query.length(); i++) {
if (query.charAt(i) == '-' && ref.charAt(i) == '-') {
numLeftClipped++;
}
 else {
break;
}
}
for (int i=query.length() - 1; i >= 0; i--) {
if (query.charAt(i) == '-' && ref.charAt(i) == '-') {
numRightClipped++;
}
 else {
break;
}
}
}