Program: 173802
Project: 173802
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 (portfolio.getShare(company) < numberToSell) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (pool.getShare(company) + numberToSell * company.getShareUnit() > bank.getPoolShareLimit()) {
      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 == unsellableCompany) {
        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)) {
    price=(sellPrices.get(companyName)).getPrice();
  }
 else {
    sellPrice=company.getCurrentSpace();
    price=sellPrice.getPrice();
    sellPrices.put(companyName,sellPrice);
  }
  moveStack.start(true);
  ReportBuffer.add(LocalText.getText("String_Node_Str",playerName,numberSold,company.getShareUnit(),numberSold * company.getShareUnit(),companyName,Bank.format(numberSold * price)));
  if (presCert != null && dumpedPlayer != null && presSharesToSell > 0) {
    ReportBuffer.add(LocalText.getText("String_Node_Str",dumpedPlayer.getName(),companyName));
    Portfolio dumpedPortfolio=dumpedPlayer.getPortfolio();
    List<PublicCertificateI> swapped=portfolio.swapPresidentCertificate(company,dumpedPortfolio);
    for (int i=0; i < presSharesToSell; i++) {
      certsToSell.add(swapped.get(i));
    }
  }
  for (  PublicCertificateI cert2 : certsToSell) {
    if (cert2 != null) {
      executeTradeCertificate(cert2,pool,cert2.getShares() * price);
    }
  }
  company.adjustSharePrice(SOLD,numberToSell,gameManager.getStockMarket());
  if (currentPlayer == company.getPresident()) {
    Player otherPlayer;
    for (int i=currentIndex + 1; i < currentIndex + numberOfPlayers; i++) {
      otherPlayer=gameManager.getPlayerByIndex(i);
      if (otherPlayer.getPortfolio().getShare(company) > portfolio.getShare(company)) {
        portfolio.swapPresidentCertificate(company,otherPlayer.getPortfolio());
        ReportBuffer.add(LocalText.getText("String_Node_Str",otherPlayer.getName(),company.getName()));
        break;
      }
    }
  }
  cashToRaise.add(-numberSold * price);
  if (cashToRaise.intValue() <= 0) {
    gameManager.finishShareSellingRound();
  }
  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 (portfolio.getShare(company) < numberToSell) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (pool.getShare(company) + numberToSell * company.getShareUnit() > bank.getPoolShareLimit()) {
      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 == unsellableCompany) {
        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)) {
    price=(sellPrices.get(companyName)).getPrice();
  }
 else {
    sellPrice=company.getCurrentSpace();
    price=sellPrice.getPrice();
    sellPrices.put(companyName,sellPrice);
  }
  moveStack.start(true);
  ReportBuffer.add(LocalText.getText("String_Node_Str",playerName,numberSold,company.getShareUnit(),numberSold * company.getShareUnit(),companyName,Bank.format(numberSold * price)));
  if (presCert != null && dumpedPlayer != null && presSharesToSell > 0) {
    ReportBuffer.add(LocalText.getText("String_Node_Str",dumpedPlayer.getName(),companyName));
    Portfolio dumpedPortfolio=dumpedPlayer.getPortfolio();
    List<PublicCertificateI> swapped=portfolio.swapPresidentCertificate(company,dumpedPortfolio);
    for (int i=0; i < presSharesToSell; i++) {
      certsToSell.add(swapped.get(i));
    }
  }
  for (  PublicCertificateI cert2 : certsToSell) {
    if (cert2 != null) {
      executeTradeCertificate(cert2,pool,cert2.getShares() * price);
    }
  }
  company.adjustSharePrice(SOLD,numberSold,gameManager.getStockMarket());
  if (currentPlayer == company.getPresident()) {
    Player otherPlayer;
    for (int i=currentIndex + 1; i < currentIndex + numberOfPlayers; i++) {
      otherPlayer=gameManager.getPlayerByIndex(i);
      if (otherPlayer.getPortfolio().getShare(company) > portfolio.getShare(company)) {
        portfolio.swapPresidentCertificate(company,otherPlayer.getPortfolio());
        ReportBuffer.add(LocalText.getText("String_Node_Str",otherPlayer.getName(),company.getName()));
        break;
      }
    }
  }
  cashToRaise.add(-numberSold * price);
  if (cashToRaise.intValue() <= 0) {
    gameManager.finishShareSellingRound();
  }
  return true;
}