Program: 173692
Project: 173692
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){
  PublicCompanyI company=action.getCompany();
  Portfolio from=action.getFromPortfolio();
  String companyName=company.getName();
  int number=action.getNumberBought();
  int shareUnit=company.getShareUnit();
  int sharePerCert=action.getSharePerCertificate();
  int shares=number * sharePerCert;
  String errMsg=null;
  int price=0;
  Portfolio portfolio=null;
  currentPlayer=getCurrentPlayer();
  while (true) {
    if (!playerName.equals(currentPlayer.getName())) {
      errMsg=LocalText.getText("String_Node_Str",playerName,currentPlayer.getName());
      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.getName());
    }
    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.booleanValue()) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (shares > from.getShare(company)) {
      errMsg=LocalText.getText("String_Node_Str",companyName,from.getName());
      break;
    }
    portfolio=operatingCompany.getPortfolio();
    int treasuryShareLimit=getGameParameterAsInt(GameDef.Parm.TREASURY_SHARE_LIMIT);
    if (portfolio.getShare(company) + shares * company.getShareUnit() > 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(LocalText.getText("String_Node_Str",companyName,shares,companyName,from.getName(),errMsg));
    return false;
  }
  if (number == 1) {
    ReportBuffer.add(LocalText.getText("String_Node_Str",companyName,shareUnit,companyName,from.getName(),Bank.format(shares * price)));
  }
 else {
    ReportBuffer.add(LocalText.getText("String_Node_Str",companyName,number,shareUnit,number * shareUnit,companyName,from.getName(),Bank.format(shares * price)));
  }
  moveStack.start(true);
  PublicCertificateI cert2;
  for (int i=0; i < number; i++) {
    cert2=from.findCertificate(company,sharePerCert,false);
    executeTradeCertificate(cert2,portfolio,cert2.getShares() * price);
  }
  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){
  PublicCompanyI company=action.getCompany();
  Portfolio from=action.getFromPortfolio();
  String companyName=company.getName();
  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;
  Portfolio portfolio=null;
  currentPlayer=getCurrentPlayer();
  while (true) {
    if (!playerName.equals(currentPlayer.getName())) {
      errMsg=LocalText.getText("String_Node_Str",playerName,currentPlayer.getName());
      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.getName());
    }
    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.booleanValue()) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (share > from.getShare(company)) {
      errMsg=LocalText.getText("String_Node_Str",companyName,from.getName());
      break;
    }
    portfolio=operatingCompany.getPortfolio();
    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(LocalText.getText("String_Node_Str",companyName,shares,companyName,from.getName(),errMsg));
    return false;
  }
  if (number == 1) {
    ReportBuffer.add(LocalText.getText("String_Node_Str",companyName,shareUnit,companyName,from.getName(),Bank.format(shares * price)));
  }
 else {
    ReportBuffer.add(LocalText.getText("String_Node_Str",companyName,number,shareUnit,number * shareUnit,companyName,from.getName(),Bank.format(shares * price)));
  }
  moveStack.start(true);
  PublicCertificateI cert2;
  for (int i=0; i < number; i++) {
    cert2=from.findCertificate(company,sharePerCert / shareUnit,false);
    executeTradeCertificate(cert2,portfolio,cert2.getShares() * price);
  }
  hasBought.set(true);
  return true;
}