Program: 173561
Project: 173561
Buggy source:
private boolean execute(MapCorrectionAction action){
  if (action.getStep() == ActionStep.FINISHED) {
    action.setNextStep(ActionStep.FINISHED);
  }
 else   if (action.getNextStep() == ActionStep.CANCELLED) {
    activeTileAction=null;
    return true;
  }
  MapHex hex=action.getLocation();
  Tile chosenTile=action.getChosenTile();
  TileManager tmgr=getParent().getTileManager();
  Tile preprintedTile=tmgr.getTile(hex.getPreprintedTiled());
  String errMsg=null;
  while (true) {
    if (chosenTile != null && rails.util.Util.hasValue(chosenTile.getExternalId()) && chosenTile != hex.getCurrentTile() && chosenTile.countFreeTiles() == 0) {
      errMsg=LocalText.getText("String_Node_Str",chosenTile.getExternalId());
      action.selectHex(hex);
      break;
    }
    List<BaseToken> baseTokens=hex.getBaseTokens();
    if (chosenTile != null && baseTokens != null && !baseTokens.isEmpty()) {
      List<Station> stations=chosenTile.getStations();
      int nbSlots=0;
      if (stations != null) {
        for (        Station station : stations) {
          nbSlots+=station.getBaseSlots();
        }
      }
      if (baseTokens.size() > nbSlots) {
        errMsg=LocalText.getText("String_Node_Str",chosenTile.getExternalId());
        action.selectHex(hex);
        break;
      }
      if (chosenTile.getNumStations() >= 2 && hex.getCurrentTile().getColourNumber() >= chosenTile.getColourNumber() || hex.getCurrentTile().relayBaseTokensOnUpgrade()) {
        errMsg=LocalText.getText("String_Node_Str",chosenTile.getExternalId());
        action.selectHex(hex);
        break;
      }
    }
    break;
  }
  if (errMsg != null) {
    DisplayBuffer.add(LocalText.getText("String_Node_Str",chosenTile.getExternalId(),hex.getId(),errMsg));
    ;
  }
  ActionStep nextStep;
  if (action.getStep() != ActionStep.FINISHED)   nextStep=action.getNextStep();
 else   nextStep=ActionStep.FINISHED;
switch (nextStep) {
case SELECT_TILE:
    List<Tile> possibleTiles=tmgr.getAllUpgrades(preprintedTile,hex);
  if (preprintedTile == hex.getCurrentTile())   possibleTiles.remove(hex.getCurrentTile());
action.setTiles(possibleTiles);
break;
case SELECT_ORIENTATION:
if (preprintedTile == chosenTile) {
action.selectOrientation(hex.getPreprintedTileRotation());
action.setNextStep(ActionStep.CONFIRM);
break;
}
 else if (chosenTile.getFixedOrientation() != -1) {
action.selectOrientation(chosenTile.getFixedOrientation());
action.setNextStep(ActionStep.CONFIRM);
break;
}
 else {
break;
}
case RELAY_BASETOKENS:
if (chosenTile.getNumStations() >= 2 && hex.getCurrentTile().getColourNumber() >= chosenTile.getColourNumber() || hex.getCurrentTile().relayBaseTokensOnUpgrade()) {
ImmutableList.Builder<BaseToken> tokens=ImmutableList.builder();
for (Stop oldStop : hex.getStops()) {
tokens.addAll(oldStop.getBaseTokens());
}
action.setTokensToRelay(tokens.build());
action.setPossibleStations(chosenTile.getStations());
break;
}
 else {
action.selectRelayBaseTokens(null);
return execute(action);
}
case FINISHED:
getRoot().getChangeStack().newChangeSet(action);
int orientation=action.getOrientation();
hex.upgrade(chosenTile,orientation,new HashMap<String,Integer>());
String msg=LocalText.getText("String_Node_Str",chosenTile.getExternalId(),hex.getId(),hex.getOrientationName(orientation));
ReportBuffer.add(msg);
getParent().addToNextPlayerMessages(msg,true);
activeTileAction=null;
break;
case CANCELLED:
activeTileAction=null;
}
if (action.getStep() != ActionStep.FINISHED) {
action.moveToNextStep();
}
return true;
}

Fixed version (ground truth):
private boolean execute(MapCorrectionAction action){
  if (action.getStep() == ActionStep.FINISHED) {
    action.setNextStep(ActionStep.FINISHED);
  }
 else   if (action.getNextStep() == ActionStep.CANCELLED) {
    activeTileAction=null;
    return true;
  }
  MapHex hex=action.getLocation();
  Tile chosenTile=action.getChosenTile();
  TileManager tmgr=getParent().getTileManager();
  Tile preprintedTile=tmgr.getTile(hex.getPreprintedTileId());
  String errMsg=null;
  while (true) {
    if (chosenTile != null && rails.util.Util.hasValue(chosenTile.getExternalId()) && chosenTile != hex.getCurrentTile() && chosenTile.countFreeTiles() == 0) {
      errMsg=LocalText.getText("String_Node_Str",chosenTile.getExternalId());
      action.selectHex(hex);
      break;
    }
    List<BaseToken> baseTokens=hex.getBaseTokens();
    if (chosenTile != null && baseTokens != null && !baseTokens.isEmpty()) {
      List<Station> stations=chosenTile.getStations();
      int nbSlots=0;
      if (stations != null) {
        for (        Station station : stations) {
          nbSlots+=station.getBaseSlots();
        }
      }
      if (baseTokens.size() > nbSlots) {
        errMsg=LocalText.getText("String_Node_Str",chosenTile.getExternalId());
        action.selectHex(hex);
        break;
      }
      if (chosenTile.getNumStations() >= 2 && hex.getCurrentTile().getColourNumber() >= chosenTile.getColourNumber() || hex.getCurrentTile().relayBaseTokensOnUpgrade()) {
        errMsg=LocalText.getText("String_Node_Str",chosenTile.getExternalId());
        action.selectHex(hex);
        break;
      }
    }
    break;
  }
  if (errMsg != null) {
    DisplayBuffer.add(LocalText.getText("String_Node_Str",chosenTile.getExternalId(),hex.getId(),errMsg));
    ;
  }
  ActionStep nextStep;
  if (action.getStep() != ActionStep.FINISHED)   nextStep=action.getNextStep();
 else   nextStep=ActionStep.FINISHED;
switch (nextStep) {
case SELECT_TILE:
    List<Tile> possibleTiles=tmgr.getAllUpgrades(preprintedTile,hex);
  if (preprintedTile == hex.getCurrentTile())   possibleTiles.remove(hex.getCurrentTile());
action.setTiles(possibleTiles);
break;
case SELECT_ORIENTATION:
if (preprintedTile == chosenTile) {
action.selectOrientation(hex.getPreprintedTileRotation());
action.setNextStep(ActionStep.CONFIRM);
break;
}
 else if (chosenTile.getFixedOrientation() != -1) {
action.selectOrientation(chosenTile.getFixedOrientation());
action.setNextStep(ActionStep.CONFIRM);
break;
}
 else {
break;
}
case RELAY_BASETOKENS:
if (chosenTile.getNumStations() >= 2 && hex.getCurrentTile().getColourNumber() >= chosenTile.getColourNumber() || hex.getCurrentTile().relayBaseTokensOnUpgrade()) {
ImmutableList.Builder<BaseToken> tokens=ImmutableList.builder();
for (Stop oldStop : hex.getStops()) {
tokens.addAll(oldStop.getBaseTokens());
}
action.setTokensToRelay(tokens.build());
action.setPossibleStations(chosenTile.getStations());
break;
}
 else {
action.selectRelayBaseTokens(null);
return execute(action);
}
case FINISHED:
getRoot().getChangeStack().newChangeSet(action);
int orientation=action.getOrientation();
hex.upgrade(chosenTile,orientation,new HashMap<String,Integer>());
String msg=LocalText.getText("String_Node_Str",chosenTile.getExternalId(),hex.getId(),hex.getOrientationName(orientation));
ReportBuffer.add(msg);
getParent().addToNextPlayerMessages(msg,true);
activeTileAction=null;
break;
case CANCELLED:
activeTileAction=null;
}
if (action.getStep() != ActionStep.FINISHED) {
action.moveToNextStep();
}
return true;
}