Program: 173527
Project: 173527
Buggy source:
/** 
 * Start a company by buying one or more shares (more applies to e.g. 1841)
 * @param player The player that wants to start a company.
 * @param company The company to start.
 * @param price The start (par) price (ignored if the price is fixed).
 * @param shares The number of shares to buy (can be more than 1 in e.g.1841).
 * @return True if the company could be started. False indicates an error.
 */
@Override public boolean startCompany(String playerName,StartCompany action){
  PublicCompany company=action.getCompany();
  int price=action.getPrice();
  int shares=action.getNumberBought();
  String errMsg=null;
  StockSpace startSpace=null;
  int numberOfCertsToBuy=0;
  PublicCertificate cert=null;
  String companyName=company.getId();
  PublicCompany minor=null;
  StartCompany_18EU startAction=null;
  Stop selectedHomeCity=null;
  currentPlayer=getCurrentPlayer();
  while (true) {
    if (!(action instanceof StartCompany_18EU)) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    startAction=(StartCompany_18EU)action;
    if (companyBoughtThisTurnWrapper.value() != null) {
      errMsg=LocalText.getText("String_Node_Str",playerName);
      break;
    }
    company=companyManager.getPublicCompany(companyName);
    if (company == null) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (company.hasStarted()) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    cert=ipo.findCertificate(company,true);
    if (shares < cert.getShares())     shares=cert.getShares();
    numberOfCertsToBuy=shares - (cert.getShares() - 1);
    if (!mayPlayerBuyCertificate(currentPlayer,company,numberOfCertsToBuy)) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if ((startSpace=stockMarket.getStartSpace(price)) == null) {
      errMsg=LocalText.getText("String_Node_Str",Currency.format(this,price),company.getId());
      break;
    }
    if (currentPlayer.getCashValue() < shares * price) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (!phase5Reached) {
      minor=startAction.getChosenMinor();
      if (minor != null && currentPlayer.getPortfolioModel().getCertificates(minor) == null) {
        errMsg=LocalText.getText("String_Node_Str",currentPlayer.getId(),minor.getId());
        break;
      }
    }
 else {
      selectedHomeCity=startAction.getSelectedHomeStation();
      if (selectedHomeCity.getSlots() <= selectedHomeCity.getBaseTokens().size()) {
        errMsg=LocalText.getText("String_Node_Str",selectedHomeCity.toString(),company.getId());
        break;
      }
    }
    numberOfCertsToBuy++;
    break;
  }
  if (errMsg != null) {
    DisplayBuffer.add(LocalText.getText("String_Node_Str",playerName,companyName,Currency.format(this,price),errMsg));
    return false;
  }
  ChangeStack.start(this,action);
  MapHex homeHex=null;
  int homeCityNumber=1;
  if (minor != null) {
    homeHex=minor.getHomeHexes().get(0);
    homeCityNumber=homeHex.getCityOfBaseToken(minor);
  }
 else   if (selectedHomeCity != null) {
    homeHex=selectedHomeCity.getParent();
    homeCityNumber=selectedHomeCity.getNumber();
  }
  company.setHomeHex(homeHex);
  company.setHomeCityNumber(homeCityNumber);
  company.start(startSpace);
  ReportBuffer.add(LocalText.getText("String_Node_Str",playerName,companyName,Currency.format(this,price),Currency.format(this,shares * price),shares,cert.getShare(),company.getId()));
  cert.moveTo(currentPlayer);
  Currency.wire(currentPlayer,shares * price,company);
  if (minor != null) {
    PublicCertificate cert2=ipo.findCertificate(company,false);
    cert2.moveTo(currentPlayer);
    int minorCash=minor.getCash();
    int minorTrains=minor.getPortfolioModel().getTrainList().size();
    company.transferAssetsFrom(minor);
    minor.setClosed();
    ReportBuffer.add(LocalText.getText("String_Node_Str",currentPlayer.getId(),minor.getId(),company.getId(),Currency.format(this,minorCash),minorTrains));
    ReportBuffer.add(LocalText.getText("String_Node_Str",currentPlayer.getId(),cert2.getShare(),company.getId(),ipo.getId(),minor.getId()));
  }
 else {
    ReportBuffer.add(LocalText.getText("String_Node_Str",company.getId(),selectedHomeCity.toString()));
  }
  Portfolio.moveAll(ipo.getCertificates(company),company);
  ReportBuffer.add(LocalText.getText("String_Node_Str",company.getPortfolioModel().getShare(company),company.getId()));
  int tokensCost=100;
  String costText=Currency.toBank(company,tokensCost);
  ReportBuffer.add(LocalText.getText("String_Node_Str",company.getId(),costText,company.getNumberOfBaseTokens()));
  companyBoughtThisTurnWrapper.set(company);
  hasActed.set(true);
  setPriority();
  return true;
}

Fixed version (ground truth):
/** 
 * Start a company by buying one or more shares (more applies to e.g. 1841)
 * @param player The player that wants to start a company.
 * @param company The company to start.
 * @param price The start (par) price (ignored if the price is fixed).
 * @param shares The number of shares to buy (can be more than 1 in e.g.1841).
 * @return True if the company could be started. False indicates an error.
 */
@Override public boolean startCompany(String playerName,StartCompany action){
  PublicCompany company=action.getCompany();
  int price=action.getPrice();
  int shares=action.getNumberBought();
  String errMsg=null;
  StockSpace startSpace=null;
  int numberOfCertsToBuy=0;
  PublicCertificate cert=null;
  String companyName=company.getId();
  PublicCompany minor=null;
  StartCompany_18EU startAction=null;
  Stop selectedHomeCity=null;
  currentPlayer=getCurrentPlayer();
  while (true) {
    if (!(action instanceof StartCompany_18EU)) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    startAction=(StartCompany_18EU)action;
    if (companyBoughtThisTurnWrapper.value() != null) {
      errMsg=LocalText.getText("String_Node_Str",playerName);
      break;
    }
    company=companyManager.getPublicCompany(companyName);
    if (company == null) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    if (company.hasStarted()) {
      errMsg=LocalText.getText("String_Node_Str",companyName);
      break;
    }
    cert=ipo.findCertificate(company,true);
    if (shares < cert.getShares())     shares=cert.getShares();
    numberOfCertsToBuy=shares - (cert.getShares() - 1);
    if (!mayPlayerBuyCertificate(currentPlayer,company,numberOfCertsToBuy)) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if ((startSpace=stockMarket.getStartSpace(price)) == null) {
      errMsg=LocalText.getText("String_Node_Str",Currency.format(this,price),company.getId());
      break;
    }
    if (currentPlayer.getCashValue() < shares * price) {
      errMsg=LocalText.getText("String_Node_Str");
      break;
    }
    if (!phase5Reached) {
      minor=startAction.getChosenMinor();
      if (minor != null && currentPlayer.getPortfolioModel().getCertificates(minor) == null) {
        errMsg=LocalText.getText("String_Node_Str",currentPlayer.getId(),minor.getId());
        break;
      }
    }
 else {
      selectedHomeCity=startAction.getSelectedHomeStation();
      if (selectedHomeCity.getSlots() <= selectedHomeCity.getBaseTokens().size()) {
        errMsg=LocalText.getText("String_Node_Str",selectedHomeCity.toString(),company.getId());
        break;
      }
    }
    numberOfCertsToBuy++;
    break;
  }
  if (errMsg != null) {
    DisplayBuffer.add(LocalText.getText("String_Node_Str",playerName,companyName,Currency.format(this,price),errMsg));
    return false;
  }
  ChangeStack.start(this,action);
  MapHex homeHex=null;
  int homeCityNumber=1;
  if (minor != null) {
    homeHex=minor.getHomeHexes().get(0);
    homeCityNumber=homeHex.getCityOfBaseToken(minor);
  }
 else   if (selectedHomeCity != null) {
    homeHex=selectedHomeCity.getParent();
    homeCityNumber=selectedHomeCity.getNumber();
  }
  company.setHomeHex(homeHex);
  company.setHomeCityNumber(homeCityNumber);
  company.start(startSpace);
  ReportBuffer.add(LocalText.getText("String_Node_Str",playerName,companyName,Currency.format(this,price),Currency.format(this,shares * price),shares,cert.getShare(),company.getId()));
  cert.moveTo(currentPlayer);
  Currency.wire(currentPlayer,shares * price,company);
  if (minor != null) {
    PublicCertificate cert2=ipo.findCertificate(company,false);
    cert2.moveTo(currentPlayer);
    int minorCash=minor.getCash();
    int minorTrains=minor.getPortfolioModel().getTrainList().size();
    company.transferAssetsFrom(minor);
    minor.setClosed();
    ReportBuffer.add(LocalText.getText("String_Node_Str",currentPlayer.getId(),minor.getId(),company.getId(),Currency.format(this,minorCash),minorTrains));
    ReportBuffer.add(LocalText.getText("String_Node_Str",currentPlayer.getId(),cert2.getShare(),company.getId(),ipo.getParent().getId(),minor.getId()));
  }
 else {
    ReportBuffer.add(LocalText.getText("String_Node_Str",company.getId(),selectedHomeCity.toString()));
  }
  Portfolio.moveAll(ipo.getCertificates(company),company);
  ReportBuffer.add(LocalText.getText("String_Node_Str",company.getPortfolioModel().getShare(company),company.getId()));
  int tokensCost=100;
  String costText=Currency.toBank(company,tokensCost);
  ReportBuffer.add(LocalText.getText("String_Node_Str",company.getId(),costText,company.getNumberOfBaseTokens()));
  companyBoughtThisTurnWrapper.set(company);
  hasActed.set(true);
  setPriority();
  return true;
}