Program: 173809
Project: 173809
Buggy source:
public boolean buyTrain(BuyTrain action){
  TrainI train=action.getTrain();
  PublicCompanyI company=action.getCompany();
  String companyName=company.getName();
  TrainI exchangedTrain=action.getExchangedTrain();
  SpecialTrainBuy stb=null;
  String errMsg=null;
  int presidentCash=action.getPresidentCashToAdd();
  boolean presidentMustSellShares=false;
  int price=action.getPricePaid();
  int actualPresidentCash=0;
  Player currentPlayer=operatingCompany.getPresident();
  ;
  while (true) {
    if (getStep() != STEP_BUY_TRAIN) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (train == null) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (price < 0) {
      errMsg=LocalText.getText("String_Node_Str",Bank.format(price));
      break;
    }
    int trainLimit=operatingCompany.getCurrentTrainLimit();
    if (!canBuyTrain()) {
      errMsg=LocalText.getText("String_Node_Str",String.valueOf(trainLimit));
      break;
    }
    if (action.mustPresidentAddCash()) {
      presidentCash=action.getPresidentCashToAdd();
      if (currentPlayer.getCash() >= presidentCash) {
        actualPresidentCash=presidentCash;
      }
 else {
        presidentMustSellShares=true;
        cashToBeRaisedByPresident=presidentCash - currentPlayer.getCash();
      }
    }
 else     if (action.mayPresidentAddCash()) {
      presidentCash=price - operatingCompany.getCash();
      if (presidentCash > action.getPresidentCashToAdd()) {
        errMsg=LocalText.getText("String_Node_Str",Bank.format(action.getPresidentCashToAdd()));
        break;
      }
 else       if (currentPlayer.getCash() >= presidentCash) {
        actualPresidentCash=presidentCash;
      }
 else {
        presidentMustSellShares=true;
        cashToBeRaisedByPresident=presidentCash - currentPlayer.getCash();
      }
    }
 else {
      if (price > operatingCompany.getCash()) {
        errMsg=LocalText.getText("String_Node_Str",new String[]{companyName,Bank.format(operatingCompany.getCash()),Bank.format(price)});
        break;
      }
    }
    stb=action.getSpecialProperty();
    break;
  }
  if (errMsg != null) {
    DisplayBuffer.add(LocalText.getText("String_Node_Str",new String[]{companyName,train.getName(),Bank.format(price),errMsg}));
    return false;
  }
  MoveSet.start(true);
  PhaseI previousPhase=getCurrentPhase();
  if (presidentMustSellShares) {
    savedAction=action;
    gameManager.startShareSellingRound(this,operatingCompany,cashToBeRaisedByPresident);
    return true;
  }
  if (actualPresidentCash > 0) {
    new CashMove(currentPlayer,operatingCompany,presidentCash);
  }
  Portfolio oldHolder=train.getHolder();
  if (exchangedTrain != null) {
    TrainI oldTrain=operatingCompany.getPortfolio().getTrainOfType(exchangedTrain.getType());
    Bank.getPool().buyTrain(oldTrain,0);
    ReportBuffer.add(LocalText.getText("String_Node_Str",new String[]{companyName,exchangedTrain.getName(),train.getName(),oldHolder.getName(),Bank.format(price)}));
  }
 else   if (stb == null) {
    ReportBuffer.add(LocalText.getText("String_Node_Str",new String[]{companyName,train.getName(),oldHolder.getName(),Bank.format(price)}));
  }
 else {
    ReportBuffer.add(LocalText.getText("String_Node_Str",new String[]{companyName,train.getName(),oldHolder.getName(),Bank.format(price),stb.getCompany().getName()}));
  }
  operatingCompany.buyTrain(train,price);
  if (oldHolder == Bank.getIpo())   train.getType().addToBoughtFromIPO();
  if (oldHolder.getOwner() instanceof Bank) {
    trainsBoughtThisTurn.add(train.getType());
  }
  if (stb != null) {
    stb.setExercised();
    log.debug("String_Node_Str");
  }
  TrainManager.get().checkTrainAvailability(train,oldHolder);
  currentPhase=getCurrentPhase();
  if (currentPhase != previousPhase && checkForExcessTrains()) {
    stepObject.set(STEP_DISCARD_TRAINS);
  }
  return true;
}

Fixed version (ground truth):
public boolean buyTrain(BuyTrain action){
  TrainI train=action.getTrain();
  PublicCompanyI company=action.getCompany();
  String companyName=company.getName();
  TrainI exchangedTrain=action.getExchangedTrain();
  SpecialTrainBuy stb=null;
  String errMsg=null;
  int presidentCash=action.getPresidentCashToAdd();
  boolean presidentMustSellShares=false;
  int price=action.getPricePaid();
  int actualPresidentCash=0;
  Player currentPlayer=operatingCompany.getPresident();
  while (true) {
    if (getStep() != STEP_BUY_TRAIN) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (train == null) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (price < 0) {
      errMsg=LocalText.getText("String_Node_Str",Bank.format(price));
      break;
    }
    int trainLimit=operatingCompany.getCurrentTrainLimit();
    if (!canBuyTrain()) {
      errMsg=LocalText.getText("String_Node_Str",String.valueOf(trainLimit));
      break;
    }
    if (action.mustPresidentAddCash()) {
      presidentCash=action.getPresidentCashToAdd();
      if (currentPlayer.getCash() >= presidentCash) {
        actualPresidentCash=presidentCash;
      }
 else {
        presidentMustSellShares=true;
        cashToBeRaisedByPresident=presidentCash - currentPlayer.getCash();
      }
    }
 else     if (action.mayPresidentAddCash()) {
      presidentCash=price - operatingCompany.getCash();
      if (presidentCash > action.getPresidentCashToAdd()) {
        errMsg=LocalText.getText("String_Node_Str",Bank.format(action.getPresidentCashToAdd()));
        break;
      }
 else       if (currentPlayer.getCash() >= presidentCash) {
        actualPresidentCash=presidentCash;
      }
 else {
        presidentMustSellShares=true;
        cashToBeRaisedByPresident=presidentCash - currentPlayer.getCash();
      }
    }
 else {
      if (price > operatingCompany.getCash()) {
        errMsg=LocalText.getText("String_Node_Str",new String[]{companyName,Bank.format(operatingCompany.getCash()),Bank.format(price)});
        break;
      }
    }
    stb=action.getSpecialProperty();
    break;
  }
  if (errMsg != null) {
    DisplayBuffer.add(LocalText.getText("String_Node_Str",new String[]{companyName,train.getName(),Bank.format(price),errMsg}));
    return false;
  }
  MoveSet.start(true);
  PhaseI previousPhase=getCurrentPhase();
  if (presidentMustSellShares) {
    savedAction=action;
    gameManager.startShareSellingRound(this,operatingCompany,cashToBeRaisedByPresident);
    return true;
  }
  if (actualPresidentCash > 0) {
    new CashMove(currentPlayer,operatingCompany,presidentCash);
  }
  Portfolio oldHolder=train.getHolder();
  if (exchangedTrain != null) {
    TrainI oldTrain=operatingCompany.getPortfolio().getTrainOfType(exchangedTrain.getType());
    Bank.getPool().buyTrain(oldTrain,0);
    ReportBuffer.add(LocalText.getText("String_Node_Str",new String[]{companyName,exchangedTrain.getName(),train.getName(),oldHolder.getName(),Bank.format(price)}));
  }
 else   if (stb == null) {
    ReportBuffer.add(LocalText.getText("String_Node_Str",new String[]{companyName,train.getName(),oldHolder.getName(),Bank.format(price)}));
  }
 else {
    ReportBuffer.add(LocalText.getText("String_Node_Str",new String[]{companyName,train.getName(),oldHolder.getName(),Bank.format(price),stb.getCompany().getName()}));
  }
  operatingCompany.buyTrain(train,price);
  if (oldHolder == Bank.getIpo()) {
    train.getType().addToBoughtFromIPO();
    if (train.getType().hasInfiniteAmount()) {
      Bank.getIpo().addTrain(train.getType().cloneTrain());
    }
  }
  if (oldHolder.getOwner() instanceof Bank) {
    trainsBoughtThisTurn.add(train.getType());
  }
  if (stb != null) {
    stb.setExercised();
    log.debug("String_Node_Str");
  }
  TrainManager.get().checkTrainAvailability(train,oldHolder);
  currentPhase=getCurrentPhase();
  if (currentPhase != previousPhase && checkForExcessTrains()) {
    stepObject.set(STEP_DISCARD_TRAINS);
  }
  return true;
}