Program: 79486
Project: 79486
Buggy source:
/** 
 * Looks up the state of all nodes in the management plane, and checks if the master is still ok. If it's not then determines which node should be promoted to master. If it is ourself, then promotes.
 */
protected void checkMaster(boolean initializing){
  ManagementPlaneSyncRecord memento=loadManagementPlaneSyncRecord(false);
  String masterNodeId=memento.getMasterNodeId();
  ManagementNodeSyncRecord masterNodeMemento=memento.getManagementNodes().get(masterNodeId);
  ManagementNodeSyncRecord ownNodeMemento=memento.getManagementNodes().get(ownNodeId);
  if (masterNodeMemento != null && masterNodeMemento.getStatus() == ManagementNodeState.MASTER && isHeartbeatOk(masterNodeMemento,ownNodeMemento)) {
    if (LOG.isTraceEnabled())     LOG.trace("String_Node_Str",masterNodeMemento.toVerboseString());
    return;
  }
 else   if (ownNodeMemento == null || !isHeartbeatOk(ownNodeMemento,ownNodeMemento)) {
    if (ownNodeMemento == null) {
      LOG.error("String_Node_Str" + ownNodeId + "String_Node_Str"+ "String_Node_Str"+ masterNodeId+ "String_Node_Str");
    }
 else {
      LOG.error("String_Node_Str" + ownNodeId + "String_Node_Str"+ "String_Node_Str"+ masterNodeId+ "String_Node_Str"+ "String_Node_Str"+ ownNodeMemento.toVerboseString());
    }
    return;
  }
 else   if (ownNodeId.equals(masterNodeId)) {
    LOG.warn("String_Node_Str" + ownNodeId + "String_Node_Str"+ "String_Node_Str"+ ownNodeMemento.toVerboseString());
    return;
  }
  ManagementNodeSyncRecord newMasterRecord=masterChooser.choose(memento,heartbeatTimeout,ownNodeId);
  String newMasterNodeId=(newMasterRecord == null) ? null : newMasterRecord.getNodeId();
  URI newMasterNodeUri=(newMasterRecord == null) ? null : newMasterRecord.getUri();
  boolean newMasterIsSelf=ownNodeId.equals(newMasterNodeId);
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str",new Object[]{(newMasterRecord == null ? "String_Node_Str" : newMasterRecord.toVerboseString()),(masterNodeMemento == null ? masterNodeId + "String_Node_Str" : masterNodeMemento.toVerboseString()),memento,ownNodeMemento.toVerboseString(),heartbeatTimeout});
  }
  if (!initializing) {
    LOG.warn("String_Node_Str" + masterNodeId + "String_Node_Str"+ (masterNodeMemento == null ? "String_Node_Str" : masterNodeMemento.getRemoteTimestamp())+ "String_Node_Str"+ "String_Node_Str"+ (newMasterNodeId == null ? "String_Node_Str" : newMasterNodeId + "String_Node_Str" + newMasterRecord.getRemoteTimestamp()+ "String_Node_Str"+ (newMasterNodeUri != null ? "String_Node_Str" + newMasterNodeUri : "String_Node_Str")+ (newMasterIsSelf ? "String_Node_Str" : "String_Node_Str")));
  }
  if (newMasterIsSelf) {
    promoteToMaster();
  }
}

Fixed version (ground truth):
/** 
 * Looks up the state of all nodes in the management plane, and checks if the master is still ok. If it's not then determines which node should be promoted to master. If it is ourself, then promotes.
 */
protected void checkMaster(boolean initializing){
  ManagementPlaneSyncRecord memento=loadManagementPlaneSyncRecord(false);
  String masterNodeId=memento.getMasterNodeId();
  ManagementNodeSyncRecord masterNodeMemento=memento.getManagementNodes().get(masterNodeId);
  ManagementNodeSyncRecord ownNodeMemento=memento.getManagementNodes().get(ownNodeId);
  ManagementNodeSyncRecord newMasterRecord=null;
  boolean demotingSelfInFavourOfOtherMaster=false;
  if (masterNodeMemento != null && masterNodeMemento.getStatus() == ManagementNodeState.MASTER && isHeartbeatOk(masterNodeMemento,ownNodeMemento)) {
    if (ownNodeId.equals(masterNodeId)) {
      if (LOG.isTraceEnabled())       LOG.trace("String_Node_Str",masterNodeMemento.toVerboseString());
      return;
    }
 else {
      if (ownNodeMemento != null && ownNodeMemento.getStatus() == ManagementNodeState.MASTER) {
        LOG.error("String_Node_Str" + ownNodeId + "String_Node_Str"+ masterNodeId);
        newMasterRecord=masterNodeMemento;
        demotingSelfInFavourOfOtherMaster=true;
      }
 else {
        if (LOG.isTraceEnabled())         LOG.trace("String_Node_Str",masterNodeMemento.toVerboseString());
        return;
      }
    }
  }
 else   if (ownNodeMemento == null || !isHeartbeatOk(ownNodeMemento,ownNodeMemento)) {
    if (ownNodeMemento == null) {
      LOG.error("String_Node_Str" + ownNodeId + "String_Node_Str"+ "String_Node_Str"+ masterNodeId+ "String_Node_Str");
    }
 else {
      LOG.error("String_Node_Str" + ownNodeId + "String_Node_Str"+ "String_Node_Str"+ masterNodeId+ "String_Node_Str"+ "String_Node_Str"+ ownNodeMemento.toVerboseString());
    }
    return;
  }
 else   if (ownNodeId.equals(masterNodeId)) {
    LOG.warn("String_Node_Str" + ownNodeId + "String_Node_Str"+ "String_Node_Str"+ ownNodeMemento.toVerboseString());
    return;
  }
  if (demotingSelfInFavourOfOtherMaster) {
    LOG.debug("String_Node_Str" + ownNodeMemento.toVerboseString() + "String_Node_Str"+ newMasterRecord);
    demoteToStandby();
    return;
  }
  newMasterRecord=masterChooser.choose(memento,heartbeatTimeout,ownNodeId);
  String newMasterNodeId=(newMasterRecord == null) ? null : newMasterRecord.getNodeId();
  URI newMasterNodeUri=(newMasterRecord == null) ? null : newMasterRecord.getUri();
  boolean newMasterIsSelf=ownNodeId.equals(newMasterNodeId);
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str",new Object[]{(newMasterRecord == null ? "String_Node_Str" : newMasterRecord.toVerboseString()),(masterNodeMemento == null ? masterNodeId + "String_Node_Str" : masterNodeMemento.toVerboseString()),memento,ownNodeMemento.toVerboseString(),heartbeatTimeout});
  }
  if (!initializing) {
    if (!demotingSelfInFavourOfOtherMaster) {
      LOG.warn("String_Node_Str" + masterNodeId + "String_Node_Str"+ (masterNodeMemento == null ? "String_Node_Str" : masterNodeMemento.getRemoteTimestamp())+ "String_Node_Str"+ "String_Node_Str"+ (newMasterNodeId == null ? "String_Node_Str" : (newMasterIsSelf ? "String_Node_Str" : "String_Node_Str") + newMasterNodeId + "String_Node_Str"+ newMasterRecord.getRemoteTimestamp()+ "String_Node_Str"+ (newMasterNodeUri != null ? "String_Node_Str" + newMasterNodeUri : "String_Node_Str")));
    }
  }
  if (newMasterIsSelf) {
    promoteToMaster();
  }
}