Program: 19902
Project: 19902
Buggy source:
/** 
 * Attaches the given unit to the given tail, expanding the unit if necessary. If an identical unit is already attached, then this path is folded into the existing path.
 * @param tail the place to attach the unit to
 * @param unitState the new unit to attach
 * @param leftContext the left context for the unit
 * @param righttContext the right context for the unit
 * @return the tail of the added unit (or null if the path wasfolded onto an already expanded path.
 */
private SentenceHMMState attachUnit(PronunciationState parent,SentenceHMMState tail,Unit[] units,int which,UnitContext leftContext,UnitContext rightContext){
  Unit[] lc=getLC(leftContext,units,which);
  Unit[] rc=getRC(units,which,rightContext);
  UnitContext actualRightContext=UnitContext.get(rc);
  LeftRightContext context=LeftRightContext.get(lc,rc);
  Unit cdUnit=Unit.getUnit(units[which].getName(),units[which].isFiller(),context);
  UnitState unitState=new ExtendedUnitState(parent,which,cdUnit);
  float logInsertionProbability;
  if (unitState.getUnit().isFiller()) {
    logInsertionProbability=logSilenceInsertionProbability;
  }
 else   if (unitState.getWhich() == 0) {
    logInsertionProbability=logWordInsertionProbability;
  }
 else {
    logInsertionProbability=logUnitInsertionProbability;
  }
  SentenceHMMState existingState=getExistingState(unitState);
  if (existingState != null) {
    attachState(tail,existingState,logOne,logOne,logInsertionProbability);
    return null;
  }
 else {
    attachState(tail,unitState,logOne,logOne,logInsertionProbability);
    addStateToCache(unitState);
    tail=expandUnit(unitState);
    if (unitState.isLast()) {
      UnitContext nextLeftContext=generateNextLeftContext(leftContext,units[which]);
      ContextPair cp=ContextPair.get(nextLeftContext,actualRightContext);
      addExitPoint(cp,tail);
      if (actualRightContext == UnitContext.SILENCE) {
        SentenceHMMState silTail;
        UnitState silUnit=new ExtendedUnitState(parent,which + 1,Unit.SILENCE);
        SentenceHMMState silExistingState=getExistingState(silUnit);
        if (silExistingState != null) {
          attachState(tail,silExistingState,logOne,logOne,logSilenceInsertionProbability);
        }
 else {
          attachState(tail,silUnit,logOne,logOne,logSilenceInsertionProbability);
          addStateToCache(silUnit);
          silTail=expandUnit(silUnit);
          ContextPair silCP=ContextPair.get(UnitContext.SILENCE,UnitContext.EMPTY);
          addExitPoint(silCP,silTail);
        }
      }
    }
    return tail;
  }
}

Fixed version (ground truth):
/** 
 * Attaches the given unit to the given tail, expanding the unit if necessary. If an identical unit is already attached, then this path is folded into the existing path.
 * @param parent the parent state
 * @param tail the place to attach the unit to
 * @param units the set of units
 * @param which the index into the set of units
 * @param leftContext the left context for the unit
 * @param rightContext the right context for the unit
 * @return the tail of the added unit (or null if the path wasfolded onto an already expanded path.
 */
private SentenceHMMState attachUnit(PronunciationState parent,SentenceHMMState tail,Unit[] units,int which,UnitContext leftContext,UnitContext rightContext){
  Unit[] lc=getLC(leftContext,units,which);
  Unit[] rc=getRC(units,which,rightContext);
  UnitContext actualRightContext=UnitContext.get(rc);
  LeftRightContext context=LeftRightContext.get(lc,rc);
  Unit cdUnit=Unit.getUnit(units[which].getName(),units[which].isFiller(),context);
  UnitState unitState=new ExtendedUnitState(parent,which,cdUnit);
  float logInsertionProbability;
  if (unitState.getUnit().isFiller()) {
    logInsertionProbability=logSilenceInsertionProbability;
  }
 else   if (unitState.getWhich() == 0) {
    logInsertionProbability=logWordInsertionProbability;
  }
 else {
    logInsertionProbability=logUnitInsertionProbability;
  }
  SentenceHMMState existingState=getExistingState(unitState);
  if (existingState != null) {
    attachState(tail,existingState,logOne,logOne,logInsertionProbability);
    return null;
  }
 else {
    attachState(tail,unitState,logOne,logOne,logInsertionProbability);
    addStateToCache(unitState);
    tail=expandUnit(unitState);
    if (unitState.isLast()) {
      UnitContext nextLeftContext=generateNextLeftContext(leftContext,units[which]);
      ContextPair cp=ContextPair.get(nextLeftContext,actualRightContext);
      addExitPoint(cp,tail);
      if (actualRightContext == UnitContext.SILENCE) {
        SentenceHMMState silTail;
        UnitState silUnit=new ExtendedUnitState(parent,which + 1,Unit.SILENCE);
        SentenceHMMState silExistingState=getExistingState(silUnit);
        if (silExistingState != null) {
          attachState(tail,silExistingState,logOne,logOne,logSilenceInsertionProbability);
        }
 else {
          attachState(tail,silUnit,logOne,logOne,logSilenceInsertionProbability);
          addStateToCache(silUnit);
          silTail=expandUnit(silUnit);
          ContextPair silCP=ContextPair.get(UnitContext.SILENCE,UnitContext.EMPTY);
          addExitPoint(silCP,silTail);
        }
      }
    }
    return tail;
  }
}