Program: 173335
Project: 173335
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();
  int currentIndex=getCurrentPlayerIndex();
  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;
      Player player=playerManager.getCurrentPlayer();
      for (int i=currentIndex + 1; i < currentIndex + numberOfPlayers; i++) {
        otherPlayer=playerManager.getNextPlayerAfter(player);
        if (otherPlayer.getPortfolioModel().getShare(company) >= presCert.getShare()) {
          if (numberToSell > 1 || otherPlayer.getPortfolioModel().ownsCertificates(company,1,false) >= 1) {
            dumpedPlayer=otherPlayer;
            presSharesToSell=numberToSell;
            numberToSell=0;
            break;
          }
        }
        player=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) - (numberSold * 5));
  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(companyName);
  adjustSharePrice(company,numberSold,soldBefore);
  if (!company.isClosed()) {
    executeShareTransfer(company,certsToSell,dumpedPlayer,presSharesToSell);
  }
  cashToRaise.add(-numberSold * price);
  if (cashToRaise.value() <= 0) {
    gameManager.finishShareSellingRound();
  }
 else   if (getSellableShares().isEmpty()) {
    gameManager.finishShareSellingRound();
  }
  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();
  int currentIndex=getCurrentPlayerIndex();
  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;
      Player player=playerManager.getCurrentPlayer();
      for (int i=currentIndex + 1; i < currentIndex + numberOfPlayers; i++) {
        otherPlayer=playerManager.getNextPlayerAfter(player);
        if (otherPlayer.getPortfolioModel().getShare(company) >= presCert.getShare()) {
          if (numberToSell > 1 || otherPlayer.getPortfolioModel().ownsCertificates(company,1,false) >= 1) {
            dumpedPlayer=otherPlayer;
            presSharesToSell=numberToSell;
            numberToSell=0;
            break;
          }
        }
        player=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) - (numberSold * 5));
  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);
  }
  cashToRaise.add(-numberSold * price);
  if (cashToRaise.value() <= 0) {
    gameManager.finishShareSellingRound();
  }
 else   if (getSellableShares().isEmpty()) {
    gameManager.finishShareSellingRound();
  }
  return true;
}