Program: 173814
Project: 173814
Buggy source:
/** 
 * Create a list of certificates that a player may buy in a Stock Round, taking all rules into account.
 * @return List of buyable certificates.
 */
public void setBuyableCerts(){
  if (!mayCurrentPlayerBuyAnything())   return;
  List<PublicCertificateI> certs;
  PublicCertificateI cert;
  PublicCompanyI comp;
  StockSpaceI stockSpace;
  Portfolio from;
  int price;
  int number;
  int playerCash=currentPlayer.getCash();
  PublicCompanyI companyBoughtThisTurn=(PublicCompanyI)companyBoughtThisTurnWrapper.getObject();
  if (companyBoughtThisTurn == null) {
    from=ipo;
    Map<String,List<PublicCertificateI>> map=from.getCertsPerCompanyMap();
    int shares;
    for (    String compName : map.keySet()) {
      certs=map.get(compName);
      if (certs == null || certs.isEmpty())       continue;
      cert=certs.get(0);
      comp=cert.getCompany();
      if (isSaleRecorded(currentPlayer,comp))       continue;
      if (currentPlayer.maxAllowedNumberOfSharesToBuy(comp,cert.getShare()) < 1)       continue;
      shares=cert.getShares();
      if (!cert.isPresidentShare()) {
        if (cert.getCertificatePrice() <= playerCash) {
          possibleActions.add(new BuyCertificate(cert,from));
        }
      }
 else       if (!comp.hasStarted()) {
        if (comp.hasParPrice()) {
          price=comp.getParPrice().getPrice() * cert.getShares();
          possibleActions.add(new StartCompany(cert,price));
        }
 else {
          List<Integer> startPrices=new ArrayList<Integer>();
          for (          int startPrice : stockMarket.getStartPrices()) {
            if (startPrice * shares <= playerCash) {
              startPrices.add(startPrice);
            }
          }
          if (startPrices.size() > 0) {
            int[] prices=new int[startPrices.size()];
            Arrays.sort(prices);
            for (int i=0; i < prices.length; i++) {
              prices[i]=startPrices.get(i);
            }
            possibleActions.add(new StartCompany(cert,prices));
          }
        }
      }
 else       if (comp.hasParPrice()) {
        price=comp.getParPrice().getPrice() * cert.getShares();
        if (price <= playerCash) {
          possibleActions.add(new BuyCertificate(cert,from,price));
        }
      }
    }
  }
  from=pool;
  Map<String,List<PublicCertificateI>> map=from.getCertsPerCompanyMap();
  for (  String compName : map.keySet()) {
    certs=map.get(compName);
    if (certs == null || certs.isEmpty())     continue;
    number=certs.size();
    cert=certs.get(0);
    comp=cert.getCompany();
    if (isSaleRecorded(currentPlayer,comp))     continue;
    if (currentPlayer.maxAllowedNumberOfSharesToBuy(comp,cert.getShare()) < 1)     continue;
    stockSpace=comp.getCurrentPrice();
    price=stockSpace.getPrice();
    if (companyBoughtThisTurn != null) {
      if (comp != companyBoughtThisTurn)       continue;
      if (!stockSpace.isNoBuyLimit())       continue;
    }
    if (!stockSpace.isNoBuyLimit()) {
      number=1;
      if (!currentPlayer.mayBuyCompanyShare(comp,number))       continue;
      if (!stockSpace.isNoCertLimit() && !currentPlayer.mayBuyCertificate(comp,number))       continue;
    }
    while (number > 0 && playerCash < number * price)     number--;
    if (number > 0) {
      possibleActions.add(new BuyCertificate(cert,from,price,number));
    }
  }
  if (gameManager.canAnyCompanyHoldShares()) {
    for (    PublicCompanyI company : companyManager.getAllPublicCompanies()) {
      certs=company.getPortfolio().getCertificatesPerCompany(company.getName());
      if (certs == null || certs.isEmpty())       continue;
      cert=certs.get(0);
      if (isSaleRecorded(currentPlayer,company))       continue;
      if (!currentPlayer.mayBuyCompanyShare(company,1))       continue;
      if (currentPlayer.maxAllowedNumberOfSharesToBuy(company,certs.get(0).getShare()) < 1)       continue;
      stockSpace=company.getCurrentPrice();
      if (!stockSpace.isNoCertLimit() && !currentPlayer.mayBuyCertificate(company,1))       continue;
      if (cert.getCertificatePrice() <= playerCash) {
        possibleActions.add(new BuyCertificate(cert,company.getPortfolio()));
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Create a list of certificates that a player may buy in a Stock Round, taking all rules into account.
 * @return List of buyable certificates.
 */
public void setBuyableCerts(){
  if (!mayCurrentPlayerBuyAnything())   return;
  List<PublicCertificateI> certs;
  PublicCertificateI cert;
  PublicCompanyI comp;
  StockSpaceI stockSpace;
  Portfolio from;
  int price;
  int number;
  int playerCash=currentPlayer.getCash();
  PublicCompanyI companyBoughtThisTurn=(PublicCompanyI)companyBoughtThisTurnWrapper.getObject();
  if (companyBoughtThisTurn == null) {
    from=ipo;
    Map<String,List<PublicCertificateI>> map=from.getCertsPerCompanyMap();
    int shares;
    for (    String compName : map.keySet()) {
      certs=map.get(compName);
      if (certs == null || certs.isEmpty())       continue;
      cert=certs.get(0);
      comp=cert.getCompany();
      if (isSaleRecorded(currentPlayer,comp))       continue;
      if (currentPlayer.maxAllowedNumberOfSharesToBuy(comp,cert.getShare()) < 1)       continue;
      shares=cert.getShares();
      if (!cert.isPresidentShare()) {
        if (cert.getCertificatePrice() <= playerCash) {
          possibleActions.add(new BuyCertificate(cert,from));
        }
      }
 else       if (!comp.hasStarted()) {
        if (comp.getParPrice() != null) {
          price=comp.getParPrice().getPrice() * cert.getShares();
          possibleActions.add(new StartCompany(cert,price));
        }
 else {
          List<Integer> startPrices=new ArrayList<Integer>();
          for (          int startPrice : stockMarket.getStartPrices()) {
            if (startPrice * shares <= playerCash) {
              startPrices.add(startPrice);
            }
          }
          if (startPrices.size() > 0) {
            int[] prices=new int[startPrices.size()];
            Arrays.sort(prices);
            for (int i=0; i < prices.length; i++) {
              prices[i]=startPrices.get(i);
            }
            possibleActions.add(new StartCompany(cert,prices));
          }
        }
      }
 else       if (comp.hasParPrice()) {
        price=comp.getParPrice().getPrice() * cert.getShares();
        if (price <= playerCash) {
          possibleActions.add(new BuyCertificate(cert,from,price));
        }
      }
    }
  }
  from=pool;
  Map<String,List<PublicCertificateI>> map=from.getCertsPerCompanyMap();
  for (  String compName : map.keySet()) {
    certs=map.get(compName);
    if (certs == null || certs.isEmpty())     continue;
    number=certs.size();
    cert=certs.get(0);
    comp=cert.getCompany();
    if (isSaleRecorded(currentPlayer,comp))     continue;
    if (currentPlayer.maxAllowedNumberOfSharesToBuy(comp,cert.getShare()) < 1)     continue;
    stockSpace=comp.getCurrentPrice();
    price=stockSpace.getPrice();
    if (companyBoughtThisTurn != null) {
      if (comp != companyBoughtThisTurn)       continue;
      if (!stockSpace.isNoBuyLimit())       continue;
    }
    if (!stockSpace.isNoBuyLimit()) {
      number=1;
      if (!currentPlayer.mayBuyCompanyShare(comp,number))       continue;
      if (!stockSpace.isNoCertLimit() && !currentPlayer.mayBuyCertificate(comp,number))       continue;
    }
    while (number > 0 && playerCash < number * price)     number--;
    if (number > 0) {
      possibleActions.add(new BuyCertificate(cert,from,price,number));
    }
  }
  if (gameManager.canAnyCompanyHoldShares()) {
    for (    PublicCompanyI company : companyManager.getAllPublicCompanies()) {
      certs=company.getPortfolio().getCertificatesPerCompany(company.getName());
      if (certs == null || certs.isEmpty())       continue;
      cert=certs.get(0);
      if (isSaleRecorded(currentPlayer,company))       continue;
      if (!currentPlayer.mayBuyCompanyShare(company,1))       continue;
      if (currentPlayer.maxAllowedNumberOfSharesToBuy(company,certs.get(0).getShare()) < 1)       continue;
      stockSpace=company.getCurrentPrice();
      if (!stockSpace.isNoCertLimit() && !currentPlayer.mayBuyCertificate(company,1))       continue;
      if (cert.getCertificatePrice() <= playerCash) {
        possibleActions.add(new BuyCertificate(cert,company.getPortfolio()));
      }
    }
  }
}