Program: 45118
Project: 45118
Buggy source:
private Form<?> createForm(String form,final String button,final BuildingType type){
  Form<?> newForm=new Form<Object>(form);
  final Building building=buildings.get(type);
  AjaxButton newButton=new AjaxButton(button){
    @Override protected void onSubmit(    AjaxRequestTarget target,    Form<?> form){
      Building building=buildings.get(type);
      if (building != null) {
        Integer newLevel=building.getLevel() + 1;
        building.setLevel(newLevel);
        buildingsDao.beginTransaction();
        buildingsDao.update(building);
        buildingsDao.commitTransaction();
        updateBildingCounter(building,this);
        info("String_Node_Str");
      }
 else {
        building=new Building();
        building.setLevel(1);
        building.setType(type);
        building.setUpgrading(false);
        building.setSquare(square);
        square.getBuildings().add(building);
        mapUser.getSquares().add(square);
        buildingsDao.beginTransaction();
        buildingsDao.insert(building);
        squareDAO.insert(square);
        mapUserDao.insert(mapUser);
        buildingsDao.commitTransaction();
        updateBildingCounter(building,this);
        buildings.put(type,building);
        info("String_Node_Str");
      }
      target.add(buildWood);
      target.add(buildClay);
      target.add(buildStable);
      target.add(buildBarracks);
      target.add(buildUpgrades);
      target.add(buildDestruction);
      target.add(buildGrain);
      target.add(buildIron);
      checkVisiblityOfLinks();
      add(barracksLink);
      add(stableLink);
      add(destructionLink);
      add(upgradeLink);
      add(troopsLink);
      add(feedbackPanel);
    }
    @Override protected void onError(    AjaxRequestTarget target,    Form<?> form){
    }
  }
;
  updateBildingCounter(building,newButton);
  newForm.add(newButton);
  return newForm;
}

Fixed version (ground truth):
private Form<?> createForm(String form,final String button,final BuildingType type){
  Form<?> newForm=new Form<Object>(form);
  final Building building=buildings.get(type);
  AjaxButton newButton=new AjaxButton(button){
    @Override protected void onSubmit(    AjaxRequestTarget target,    Form<?> form){
      Building building=buildings.get(type);
      if (building != null) {
        Integer newLevel=building.getLevel() + 1;
        building.setLevel(newLevel);
        buildingsDao.beginTransaction();
        buildingsDao.update(building);
        buildingsDao.commitTransaction();
        updateBildingCounter(building,this);
        info("String_Node_Str");
      }
 else {
        building=new Building();
        building.setLevel(1);
        building.setType(type);
        building.setUpgrading(false);
        building.setSquare(square);
        square.getBuildings().add(building);
        mapUser.getSquares().add(square);
        buildingsDao.beginTransaction();
        buildingsDao.insert(building);
        squareDao.insert(square);
        mapUserDao.insert(mapUser);
        buildingsDao.commitTransaction();
        updateBildingCounter(building,this);
        buildings.put(type,building);
        info("String_Node_Str");
      }
      target.add(buildWood);
      target.add(buildClay);
      target.add(buildStable);
      target.add(buildBarracks);
      target.add(buildUpgrades);
      target.add(buildDestruction);
      target.add(buildGrain);
      target.add(buildIron);
      checkVisiblityOfLinks();
      add(barracksLink);
      add(stableLink);
      add(destructionLink);
      add(upgradeLink);
      add(troopsLink);
      add(feedbackPanel);
    }
    @Override protected void onError(    AjaxRequestTarget target,    Form<?> form){
    }
  }
;
  updateBildingCounter(building,newButton);
  newForm.add(newButton);
  return newForm;
}