Program: 173422
Project: 173422
Buggy source:
@Override public boolean sellShares(SellShares action){
  PortfolioModel portfolio=currentPlayer.getPortfolioModel();
  String playerName=currentPlayer.getId();
  String errMsg=null;
  String companyName=action.getCompanyName();
  PublicCompany company=companyManager.getPublicCompany(action.getCompanyName());
  PublicCertificate cert=null;
  PublicCertificate presCert=null;
  List<PublicCertificate> certsToSell=new ArrayList<PublicCertificate>();
  Player dumpedPlayer=null;
  int presSharesToSell=0;
  int numberToSell=action.getNumber();
  int shareUnits=action.getShareUnits();
  while (true) {
    if (numberToSell <= 0) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (company == null) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (!mayPlayerSellShareOfCompany(company)) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (portfolio.getShare(company) < numberToSell) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (pool.getShare(company) + numberToSell * company.getShareUnit() > getGameParameterAsInt(GameDef.Parm.POOL_SHARE_LIMIT)) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    Iterator<PublicCertificate> it=portfolio.getCertificates(company).iterator();
    while (numberToSell > 0 && it.hasNext()) {
      cert=it.next();
      if (cert.isPresidentShare()) {
        if (cert.isPresidentShare())         presCert=cert;
        continue;
      }
 else       if (shareUnits != cert.getShares()) {
        continue;
      }
      certsToSell.add(cert);
      numberToSell--;
    }
    if (numberToSell == 0)     presCert=null;
    if (numberToSell > 0 && presCert != null && numberToSell <= presCert.getShares()) {
      if (company == cashNeedingCompany || !dumpOtherCompaniesAllowed) {
        errMsg=LocalText.getText("String_Node_Str");
        break;
      }
      Player otherPlayer, previousPlayer;
      previousPlayer=getRoot().getPlayerManager().getCurrentPlayer();
      for (int i=1; i <= numberOfPlayers; i++) {
        otherPlayer=getRoot().getPlayerManager().getNextPlayerAfter(previousPlayer);
        if (otherPlayer.getPortfolioModel().getShare(company) >= presCert.getShare()) {
          if (numberToSell > 1 || otherPlayer.getPortfolioModel().ownsCertificates(company,1,false) >= 1) {
            dumpedPlayer=otherPlayer;
            presSharesToSell=numberToSell;
            numberToSell=0;
            break;
          }
        }
        previousPlayer=otherPlayer;
      }
    }
    if (numberToSell > 0) {
      if (presCert != null) {
        errMsg=LocalText.getText("String_Node_Str");
      }
 else {
        errMsg=LocalText.getText("String_Node_Str");
      }
      break;
    }
    break;
  }
  int numberSold=action.getNumber();
  if (errMsg != null) {
    DisplayBuffer.add(this,LocalText.getText("String_Node_Str",playerName,numberSold,companyName,errMsg));
    return false;
  }
  StockSpace sellPrice;
  int price;
  if (sellPrices.containsKey(company) && GameOption.getAsBoolean(this,"String_Node_Str")) {
    price=(sellPrices.get(company).getPrice());
  }
 else {
    sellPrice=company.getCurrentSpace();
    price=sellPrice.getPrice();
    sellPrices.put(company,sellPrice);
  }
  int cashAmount=numberSold * price * shareUnits;
  String cashText=Currency.fromBank(cashAmount,currentPlayer);
  ReportBuffer.add(this,LocalText.getText("String_Node_Str",playerName,numberSold,company.getShareUnit(),numberSold * company.getShareUnit(),companyName,cashText));
  boolean soldBefore=sellPrices.containsKey(company);
  adjustSharePrice(company,numberSold,soldBefore);
  if (!company.isClosed()) {
    executeShareTransfer(company,certsToSell,dumpedPlayer,presSharesToSell,action.getPresidentExchange());
  }
  cashToRaise.add(-numberSold * price);
  if (cashToRaise.value() <= 0) {
    gameManager.finishShareSellingRound();
  }
 else   if (getSellableShares().isEmpty()) {
    DisplayBuffer.add(this,LocalText.getText("String_Node_Str",Bank.format(this,cashToRaise.value())));
    currentPlayer.setBankrupt();
    gameManager.registerBankruptcy();
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean sellShares(SellShares action){
  PortfolioModel portfolio=currentPlayer.getPortfolioModel();
  String playerName=currentPlayer.getId();
  String errMsg=null;
  String companyName=action.getCompanyName();
  PublicCompany company=companyManager.getPublicCompany(action.getCompanyName());
  PublicCertificate cert=null;
  PublicCertificate presCert=null;
  List<PublicCertificate> certsToSell=new ArrayList<PublicCertificate>();
  Player dumpedPlayer=null;
  int presSharesToSell=0;
  int numberToSell=action.getNumber();
  int shareUnits=action.getShareUnits();
  while (true) {
    if (numberToSell <= 0) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (company == null) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (!mayPlayerSellShareOfCompany(company)) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (portfolio.getShare(company) < numberToSell) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (pool.getShare(company) + numberToSell * company.getShareUnit() > getGameParameterAsInt(GameDef.Parm.POOL_SHARE_LIMIT)) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    Iterator<PublicCertificate> it=portfolio.getCertificates(company).iterator();
    while (numberToSell > 0 && it.hasNext()) {
      cert=it.next();
      if (cert.isPresidentShare()) {
        if (cert.isPresidentShare())         presCert=cert;
        continue;
      }
 else       if (shareUnits != cert.getShares()) {
        continue;
      }
      certsToSell.add(cert);
      numberToSell--;
    }
    if (numberToSell == 0)     presCert=null;
    if (numberToSell > 0 && presCert != null && numberToSell <= presCert.getShares()) {
      if (company == cashNeedingCompany || !dumpOtherCompaniesAllowed) {
        errMsg=LocalText.getText("String_Node_Str");
        break;
      }
      Player otherPlayer, previousPlayer;
      previousPlayer=getRoot().getPlayerManager().getCurrentPlayer();
      for (int i=0; i <= numberOfPlayers; i++) {
        otherPlayer=getRoot().getPlayerManager().getNextPlayerAfter(previousPlayer);
        if (otherPlayer.getPortfolioModel().getShare(company) >= presCert.getShare()) {
          if (numberToSell > 1 || otherPlayer.getPortfolioModel().ownsCertificates(company,1,false) >= 1) {
            dumpedPlayer=otherPlayer;
            presSharesToSell=numberToSell;
            numberToSell=0;
            break;
          }
        }
        previousPlayer=otherPlayer;
      }
    }
    if (numberToSell > 0) {
      if (presCert != null) {
        errMsg=LocalText.getText("String_Node_Str");
      }
 else {
        errMsg=LocalText.getText("String_Node_Str");
      }
      break;
    }
    break;
  }
  int numberSold=action.getNumber();
  if (errMsg != null) {
    DisplayBuffer.add(this,LocalText.getText("String_Node_Str",playerName,numberSold,companyName,errMsg));
    return false;
  }
  StockSpace sellPrice;
  int price;
  if (sellPrices.containsKey(company) && GameOption.getAsBoolean(this,"String_Node_Str")) {
    price=(sellPrices.get(company).getPrice());
  }
 else {
    sellPrice=company.getCurrentSpace();
    price=sellPrice.getPrice();
    sellPrices.put(company,sellPrice);
  }
  int cashAmount=numberSold * price * shareUnits;
  String cashText=Currency.fromBank(cashAmount,currentPlayer);
  ReportBuffer.add(this,LocalText.getText("String_Node_Str",playerName,numberSold,company.getShareUnit(),numberSold * company.getShareUnit(),companyName,cashText));
  boolean soldBefore=sellPrices.containsKey(company);
  adjustSharePrice(company,numberSold,soldBefore);
  if (!company.isClosed()) {
    executeShareTransfer(company,certsToSell,dumpedPlayer,presSharesToSell,action.getPresidentExchange());
  }
  cashToRaise.add(-numberSold * price);
  if (cashToRaise.value() <= 0) {
    gameManager.finishShareSellingRound();
  }
 else   if (getSellableShares().isEmpty()) {
    DisplayBuffer.add(this,LocalText.getText("String_Node_Str",Bank.format(this,cashToRaise.value())));
    currentPlayer.setBankrupt();
    gameManager.registerBankruptcy();
  }
  return true;
}