Program: 173650
Project: 173650
Buggy source:
@Override public boolean sellShares(SellShares action){
  Portfolio portfolio=currentPlayer.getPortfolio();
  String playerName=currentPlayer.getName();
  String errMsg=null;
  String companyName=action.getCompanyName();
  PublicCompanyI company=companyManager.getPublicCompany(action.getCompanyName());
  PublicCertificateI cert=null;
  PublicCertificateI presCert=null;
  List<PublicCertificateI> certsToSell=new ArrayList<PublicCertificateI>();
  Player dumpedPlayer=null;
  int presSharesToSell=0;
  int numberToSell=action.getNumberSold();
  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<PublicCertificateI> it=portfolio.getCertificatesPerCompany(companyName).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;
      for (int i=currentIndex + 1; i < currentIndex + numberOfPlayers; i++) {
        otherPlayer=gameManager.getPlayerByIndex(i);
        if (otherPlayer.getPortfolio().getShare(company) >= presCert.getShare()) {
          if (numberToSell > 1 || otherPlayer.getPortfolio().ownsCertificates(company,1,false) >= 1) {
            dumpedPlayer=otherPlayer;
            presSharesToSell=numberToSell;
            numberToSell=0;
            break;
          }
        }
      }
    }
    if (numberToSell > 0) {
      if (presCert != null) {
        errMsg=LocalText.getText("String_Node_Str");
      }
 else {
        errMsg=LocalText.getText("String_Node_Str");
      }
      break;
    }
    break;
  }
  int numberSold=action.getNumberSold();
  if (errMsg != null) {
    DisplayBuffer.add(LocalText.getText("String_Node_Str",playerName,numberSold,companyName,errMsg));
    return false;
  }
  StockSpaceI sellPrice;
  int price;
  if (sellPrices.containsKey(companyName) && GameOption.convertValueToBoolean(getGameOption("String_Node_Str"))) {
    price=(sellPrices.get(companyName)).getPrice();
  }
 else {
    sellPrice=company.getCurrentSpace();
    price=sellPrice.getPrice();
    sellPrices.put(companyName,sellPrice);
  }
  int cashAmount=numberSold * price * shareUnits;
  moveStack.start(true).linkToPreviousMoveSet();
  ReportBuffer.add(LocalText.getText("String_Node_Str",playerName,numberSold,company.getShareUnit(),numberSold * company.getShareUnit(),companyName,Bank.format(cashAmount)));
  boolean soldBefore=sellPrices.containsKey(companyName);
  pay(bank,company,cashAmount);
  adjustSharePrice(company,numberSold,soldBefore);
  if (!company.isClosed()) {
    executeShareTransfer(company,certsToSell,dumpedPlayer,presSharesToSell);
  }
  cashToRaise.add(-numberSold * price);
  if (cashToRaise.intValue() <= 0) {
    gameManager.finishShareSellingRound();
  }
 else   if (getSellableShares().isEmpty()) {
    DisplayBuffer.add(LocalText.getText("String_Node_Str",Bank.format(cashToRaise.intValue())));
    currentPlayer.setBankrupt();
    gameManager.registerBankruptcy();
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean sellShares(SellShares action){
  Portfolio portfolio=currentPlayer.getPortfolio();
  String playerName=currentPlayer.getName();
  String errMsg=null;
  String companyName=action.getCompanyName();
  PublicCompanyI company=companyManager.getPublicCompany(action.getCompanyName());
  PublicCertificateI cert=null;
  PublicCertificateI presCert=null;
  List<PublicCertificateI> certsToSell=new ArrayList<PublicCertificateI>();
  Player dumpedPlayer=null;
  int presSharesToSell=0;
  int numberToSell=action.getNumberSold();
  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<PublicCertificateI> it=portfolio.getCertificatesPerCompany(companyName).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;
      for (int i=currentIndex + 1; i < currentIndex + numberOfPlayers; i++) {
        otherPlayer=gameManager.getPlayerByIndex(i);
        if (otherPlayer.getPortfolio().getShare(company) >= presCert.getShare()) {
          if (numberToSell > 1 || otherPlayer.getPortfolio().ownsCertificates(company,1,false) >= 1) {
            dumpedPlayer=otherPlayer;
            presSharesToSell=numberToSell;
            numberToSell=0;
            break;
          }
        }
      }
    }
    if (numberToSell > 0) {
      if (presCert != null) {
        errMsg=LocalText.getText("String_Node_Str");
      }
 else {
        errMsg=LocalText.getText("String_Node_Str");
      }
      break;
    }
    break;
  }
  int numberSold=action.getNumberSold();
  if (errMsg != null) {
    DisplayBuffer.add(LocalText.getText("String_Node_Str",playerName,numberSold,companyName,errMsg));
    return false;
  }
  StockSpaceI sellPrice;
  int price;
  if (sellPrices.containsKey(companyName) && GameOption.convertValueToBoolean(getGameOption("String_Node_Str"))) {
    price=(sellPrices.get(companyName)).getPrice();
  }
 else {
    sellPrice=company.getCurrentSpace();
    price=sellPrice.getPrice();
    sellPrices.put(companyName,sellPrice);
  }
  int cashAmount=numberSold * price * shareUnits;
  moveStack.start(true).linkToPreviousMoveSet();
  ReportBuffer.add(LocalText.getText("String_Node_Str",playerName,numberSold,company.getShareUnit(),numberSold * company.getShareUnit(),companyName,Bank.format(cashAmount)));
  boolean soldBefore=sellPrices.containsKey(companyName);
  pay(bank,currentPlayer,cashAmount);
  adjustSharePrice(company,numberSold,soldBefore);
  if (!company.isClosed()) {
    executeShareTransfer(company,certsToSell,dumpedPlayer,presSharesToSell);
  }
  cashToRaise.add(-numberSold * price);
  if (cashToRaise.intValue() <= 0) {
    gameManager.finishShareSellingRound();
  }
 else   if (getSellableShares().isEmpty()) {
    DisplayBuffer.add(LocalText.getText("String_Node_Str",Bank.format(cashToRaise.intValue())));
    currentPlayer.setBankrupt();
    gameManager.registerBankruptcy();
  }
  return true;
}