Program: 2814
Project: 2814
Buggy source:
/** 
 * Returns the directionality of the last character with strong directionality in the string, or Dir.UNKNOWN if none was encountered. For efficiency, actually scans backwards from the end of the string. Treats a non-BN character between an LRE/RLE/LRO/RLO and its matching PDF as a strong character, LTR after LRE/LRO, and RTL after RLE/RLO. The results are undefined for a string containing unbalanced LRE/RLE/LRO/RLO/PDF characters.
 */
Dir getExitDir(){
  charIndex=length;
  int embeddingLevel=0;
  int lastNonEmptyEmbeddingLevel=0;
  while (charIndex > 0) {
switch (dirTypeBackward()) {
case Character.DIRECTIONALITY_LEFT_TO_RIGHT:
      if (embeddingLevel == 0) {
        return Dir.LTR;
      }
    if (lastNonEmptyEmbeddingLevel == 0) {
      lastNonEmptyEmbeddingLevel=embeddingLevel;
    }
  break;
case Character.DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING:
case Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE:
if (lastNonEmptyEmbeddingLevel == embeddingLevel) {
  return Dir.LTR;
}
--embeddingLevel;
break;
case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:
if (embeddingLevel == 0) {
return Dir.RTL;
}
if (lastNonEmptyEmbeddingLevel == 0) {
lastNonEmptyEmbeddingLevel=embeddingLevel;
}
break;
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING:
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE:
if (lastNonEmptyEmbeddingLevel == embeddingLevel) {
return Dir.RTL;
}
--embeddingLevel;
break;
case Character.DIRECTIONALITY_POP_DIRECTIONAL_FORMAT:
++embeddingLevel;
break;
case Character.DIRECTIONALITY_BOUNDARY_NEUTRAL:
break;
default :
if (lastNonEmptyEmbeddingLevel == 0) {
lastNonEmptyEmbeddingLevel=embeddingLevel;
}
break;
}
}
return Dir.UNKNOWN;
}

Fixed version (ground truth):
/** 
 * Returns the directionality of the last character with strong directionality in the string, or DIR_UNKNOWN if none was encountered. For efficiency, actually scans backwards from the end of the string. Treats a non-BN character between an LRE/RLE/LRO/RLO and its matching PDF as a strong character, LTR after LRE/LRO, and RTL after RLE/RLO. The results are undefined for a string containing unbalanced LRE/RLE/LRO/RLO/PDF characters.
 */
int getExitDir(){
  charIndex=length;
  int embeddingLevel=0;
  int lastNonEmptyEmbeddingLevel=0;
  while (charIndex > 0) {
switch (dirTypeBackward()) {
case Character.DIRECTIONALITY_LEFT_TO_RIGHT:
      if (embeddingLevel == 0) {
        return DIR_LTR;
      }
    if (lastNonEmptyEmbeddingLevel == 0) {
      lastNonEmptyEmbeddingLevel=embeddingLevel;
    }
  break;
case Character.DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING:
case Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE:
if (lastNonEmptyEmbeddingLevel == embeddingLevel) {
  return DIR_LTR;
}
--embeddingLevel;
break;
case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:
if (embeddingLevel == 0) {
return DIR_RTL;
}
if (lastNonEmptyEmbeddingLevel == 0) {
lastNonEmptyEmbeddingLevel=embeddingLevel;
}
break;
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING:
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE:
if (lastNonEmptyEmbeddingLevel == embeddingLevel) {
return DIR_RTL;
}
--embeddingLevel;
break;
case Character.DIRECTIONALITY_POP_DIRECTIONAL_FORMAT:
++embeddingLevel;
break;
case Character.DIRECTIONALITY_BOUNDARY_NEUTRAL:
break;
default :
if (lastNonEmptyEmbeddingLevel == 0) {
lastNonEmptyEmbeddingLevel=embeddingLevel;
}
break;
}
}
return DIR_UNKNOWN;
}