Program: 173321
Project: 173321
Buggy source:
/** 
 * Buying one or more single or double-share certificates (more is sometimes possible)
 * @param player The player that wants to buy shares.
 * @param action The executed action
 * @return True if the certificates could be bought. False indicates anerror.
 */
@Override public boolean buyShares(String playerName,BuyCertificate action){
  PublicCompany company=action.getCompany();
  PortfolioModel from=action.getFromPortfolio();
  String companyName=company.getId();
  int number=action.getNumberBought();
  int shareUnit=company.getShareUnit();
  int sharePerCert=action.getSharePerCertificate();
  int share=number * sharePerCert;
  int shares=share / shareUnit;
  String errMsg=null;
  int price=0;
  PortfolioModel portfolio=null;
  currentPlayer=playerManager.getCurrentPlayer();
  while (true) {
    if (!playerName.equals(currentPlayer.getId())) {
      errMsg=LocalText.getText("String_Node_Str",playerName,currentPlayer.getId());
      break;
    }
    company=companyManager.getPublicCompany(companyName);
    if (company == null) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (company != operatingCompany) {
      errMsg=LocalText.getText("String_Node_Str",companyName,operatingCompany.getId());
    }
    if (!company.hasFloated()) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (company.mustHaveOperatedToTradeShares() && !company.hasOperated()) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (hasSold.value()) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (share > from.getShare(company)) {
      errMsg=LocalText.getText("String_Node_Str",companyName,from.getId());
      break;
    }
    portfolio=operatingCompany.getPortfolioModel();
    int treasuryShareLimit=getGameParameterAsInt(GameDef.Parm.TREASURY_SHARE_LIMIT);
    if (portfolio.getShare(company) + share > treasuryShareLimit) {
      errMsg=LocalText.getText("String_Node_Str",String.valueOf(treasuryShareLimit));
      break;
    }
    price=company.getMarketPrice();
    if (operatingCompany.getCash() < shares * price) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    break;
  }
  if (errMsg != null) {
    DisplayBuffer.add(this,LocalText.getText("String_Node_Str",companyName,shares,companyName,from.getId(),errMsg));
    return false;
  }
  int cashAmount=shares * price;
  String cashText=Currency.toBank(company,cashAmount);
  if (number == 1) {
    ReportBuffer.add(this,LocalText.getText("String_Node_Str",companyName,shareUnit,companyName,from.getId(),cashText));
  }
 else {
    ReportBuffer.add(this,LocalText.getText("String_Node_Str",companyName,number,shareUnit,number * shareUnit,companyName,from.getId(),cashText));
  }
  PublicCertificate cert2;
  for (int i=0; i < number; i++) {
    cert2=from.findCertificate(company,sharePerCert / shareUnit,false);
    cert2.moveTo(company);
  }
  hasBought.set(true);
  return true;
}

Fixed version (ground truth):
/** 
 * Buying one or more single or double-share certificates (more is sometimes possible)
 * @param player The player that wants to buy shares.
 * @param action The executed action
 * @return True if the certificates could be bought. False indicates anerror.
 */
@Override public boolean buyShares(String playerName,BuyCertificate action){
  PublicCompany company=action.getCompany();
  PortfolioModel from=action.getFromPortfolio();
  String companyName=company.getId();
  int number=action.getNumberBought();
  int shareUnit=company.getShareUnit();
  int sharePerCert=action.getSharePerCertificate();
  int share=number * sharePerCert;
  int shares=share / shareUnit;
  String errMsg=null;
  int price=0;
  PortfolioModel portfolio=null;
  currentPlayer=playerManager.getCurrentPlayer();
  while (true) {
    if (!playerName.equals(currentPlayer.getId())) {
      errMsg=LocalText.getText("String_Node_Str",playerName,currentPlayer.getId());
      break;
    }
    company=companyManager.getPublicCompany(companyName);
    if (company == null) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (company != operatingCompany) {
      errMsg=LocalText.getText("String_Node_Str",companyName,operatingCompany.getId());
    }
    if (!company.hasFloated()) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (company.mustHaveOperatedToTradeShares() && !company.hasOperated()) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (hasSold.value()) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (share > from.getShare(company)) {
      errMsg=LocalText.getText("String_Node_Str",companyName,from.getId());
      break;
    }
    portfolio=operatingCompany.getPortfolioModel();
    int treasuryShareLimit=getGameParameterAsInt(GameDef.Parm.TREASURY_SHARE_LIMIT);
    if (portfolio.getShare(company) + share > treasuryShareLimit) {
      errMsg=LocalText.getText("String_Node_Str",String.valueOf(treasuryShareLimit));
      break;
    }
    price=company.getMarketPrice();
    if (operatingCompany.getCash() < shares * price) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    break;
  }
  if (errMsg != null) {
    DisplayBuffer.add(this,LocalText.getText("String_Node_Str",companyName,shares,companyName,from.getId(),errMsg));
    return false;
  }
  int cashAmount=shares * price;
  String cashText=Currency.toBank(company,cashAmount);
  if (number == 1) {
    ReportBuffer.add(this,LocalText.getText("String_Node_Str",companyName,shareUnit,companyName,from.getName(),cashText));
  }
 else {
    ReportBuffer.add(this,LocalText.getText("String_Node_Str",companyName,number,shareUnit,number * shareUnit,companyName,from.getName(),cashText));
  }
  PublicCertificate cert2;
  for (int i=0; i < number; i++) {
    cert2=from.findCertificate(company,sharePerCert / shareUnit,false);
    cert2.moveTo(company);
  }
  hasBought.set(true);
  return true;
}