Program: 58366
Project: 58366
Buggy source:
private boolean applyGeneralFieldRules(){
  int block_count, i, j, k;
  encodeMode current, next, last;
  int[] blockLength=new int[200];
  encodeMode[] blockType=new encodeMode[200];
  block_count=0;
  blockLength[block_count]=1;
  blockType[block_count]=general_field_type[0];
  for (i=1; i < general_field.length(); i++) {
    current=general_field_type[i];
    last=general_field_type[i - 1];
    if (current == last) {
      blockLength[block_count]=blockLength[block_count] + 1;
    }
 else {
      block_count++;
      blockLength[block_count]=1;
      blockType[block_count]=general_field_type[i];
    }
  }
  block_count++;
  for (i=0; i < block_count; i++) {
    current=blockType[i];
    next=blockType[i + 1];
    if ((current == encodeMode.ISOIEC) && (i != (block_count - 1))) {
      if ((next == encodeMode.ANY_ENC) && (blockLength[i + 1] >= 4)) {
        blockType[i + 1]=encodeMode.NUMERIC;
      }
      if ((next == encodeMode.ANY_ENC) && (blockLength[i + 1] < 4)) {
        blockType[i + 1]=encodeMode.ISOIEC;
      }
      if ((next == encodeMode.ALPHA_OR_ISO) && (blockLength[i + 1] >= 5)) {
        blockType[i + 1]=encodeMode.ALPHA;
      }
      if ((next == encodeMode.ALPHA_OR_ISO) && (blockLength[i + 1] < 5)) {
        blockType[i + 1]=encodeMode.ISOIEC;
      }
    }
    if (current == encodeMode.ALPHA_OR_ISO) {
      blockType[i]=encodeMode.ALPHA;
    }
    if ((current == encodeMode.ALPHA) && (i != (block_count - 1))) {
      if ((next == encodeMode.ANY_ENC) && (blockLength[i + 1] >= 6)) {
        blockType[i + 1]=encodeMode.NUMERIC;
      }
      if ((next == encodeMode.ANY_ENC) && (blockLength[i + 1] < 6)) {
        if ((i == block_count - 2) && (blockLength[i + 1] >= 4)) {
          blockType[i + 1]=encodeMode.NUMERIC;
        }
 else {
          blockType[i + 1]=encodeMode.ALPHA;
        }
      }
    }
    if (current == encodeMode.ANY_ENC) {
      blockType[i]=encodeMode.NUMERIC;
    }
  }
  if (block_count > 1) {
    i=1;
    while (i < block_count) {
      if (blockType[i - 1] == blockType[i]) {
        blockLength[i - 1]=blockLength[i - 1] + blockLength[i];
        j=i + 1;
        while (j < block_count) {
          blockLength[j - 1]=blockLength[j];
          blockType[j - 1]=blockType[j];
          j++;
        }
        block_count--;
        i--;
      }
      i++;
    }
  }
  for (i=0; i < block_count - 1; i++) {
    if ((blockType[i] == encodeMode.NUMERIC) && ((blockLength[i] & 1) != 0)) {
      blockLength[i]=blockLength[i] - 1;
      blockLength[i + 1]=blockLength[i + 1] + 1;
    }
  }
  j=0;
  for (i=0; i < block_count; i++) {
    for (k=0; k < blockLength[i]; k++) {
      general_field_type[j]=blockType[i];
      j++;
    }
  }
  if ((blockType[block_count - 1] == encodeMode.NUMERIC) && ((blockLength[block_count - 1] & 1) != 0)) {
    return true;
  }
 else {
    return false;
  }
}

Fixed version (ground truth):
private boolean applyGeneralFieldRules(){
  int block_count, i, j, k;
  encodeMode current, next, last;
  int[] blockLength=new int[200];
  encodeMode[] blockType=new encodeMode[200];
  block_count=0;
  blockLength[block_count]=1;
  blockType[block_count]=general_field_type[0];
  for (i=1; i < general_field.length(); i++) {
    current=general_field_type[i];
    last=general_field_type[i - 1];
    if (current == last) {
      blockLength[block_count]=blockLength[block_count] + 1;
    }
 else {
      block_count++;
      blockLength[block_count]=1;
      blockType[block_count]=general_field_type[i];
    }
  }
  block_count++;
  for (i=0; i < block_count; i++) {
    current=blockType[i];
    next=blockType[i + 1];
    if ((current == encodeMode.ISOIEC) && (i != (block_count - 1))) {
      if ((next == encodeMode.ANY_ENC) && (blockLength[i + 1] >= 4)) {
        blockType[i + 1]=encodeMode.NUMERIC;
      }
      if ((next == encodeMode.ANY_ENC) && (blockLength[i + 1] < 4)) {
        blockType[i + 1]=encodeMode.ISOIEC;
      }
      if ((next == encodeMode.ALPHA_OR_ISO) && (blockLength[i + 1] >= 5)) {
        blockType[i + 1]=encodeMode.ALPHA;
      }
      if ((next == encodeMode.ALPHA_OR_ISO) && (blockLength[i + 1] < 5)) {
        blockType[i + 1]=encodeMode.ISOIEC;
      }
    }
    if (current == encodeMode.ALPHA_OR_ISO) {
      blockType[i]=encodeMode.ALPHA;
      current=encodeMode.ALPHA;
    }
    if ((current == encodeMode.ALPHA) && (i != (block_count - 1))) {
      if ((next == encodeMode.ANY_ENC) && (blockLength[i + 1] >= 6)) {
        blockType[i + 1]=encodeMode.NUMERIC;
      }
      if ((next == encodeMode.ANY_ENC) && (blockLength[i + 1] < 6)) {
        if ((i == block_count - 2) && (blockLength[i + 1] >= 4)) {
          blockType[i + 1]=encodeMode.NUMERIC;
        }
 else {
          blockType[i + 1]=encodeMode.ALPHA;
        }
      }
    }
    if (current == encodeMode.ANY_ENC) {
      blockType[i]=encodeMode.NUMERIC;
    }
  }
  if (block_count > 1) {
    i=1;
    while (i < block_count) {
      if (blockType[i - 1] == blockType[i]) {
        blockLength[i - 1]=blockLength[i - 1] + blockLength[i];
        j=i + 1;
        while (j < block_count) {
          blockLength[j - 1]=blockLength[j];
          blockType[j - 1]=blockType[j];
          j++;
        }
        block_count--;
        i--;
      }
      i++;
    }
  }
  for (i=0; i < block_count - 1; i++) {
    if ((blockType[i] == encodeMode.NUMERIC) && ((blockLength[i] & 1) != 0)) {
      blockLength[i]=blockLength[i] - 1;
      blockLength[i + 1]=blockLength[i + 1] + 1;
    }
  }
  j=0;
  for (i=0; i < block_count; i++) {
    for (k=0; k < blockLength[i]; k++) {
      general_field_type[j]=blockType[i];
      j++;
    }
  }
  if ((blockType[block_count - 1] == encodeMode.NUMERIC) && ((blockLength[block_count - 1] & 1) != 0)) {
    return true;
  }
 else {
    return false;
  }
}