Program: 89645
Project: 89645
Buggy source:
protected void upgrade(String dbVersion,String currentVersion){
  s_logger.info("String_Node_Str" + dbVersion + "String_Node_Str"+ currentVersion);
  String trimmedDbVersion=Version.trimToPatch(dbVersion);
  String trimmedCurrentVersion=Version.trimToPatch(currentVersion);
  DbUpgrade[] upgrades=_upgradeMap.get(trimmedDbVersion);
  if (upgrades == null) {
    s_logger.error("String_Node_Str" + dbVersion + "String_Node_Str"+ currentVersion);
    throw new CloudRuntimeException("String_Node_Str" + dbVersion + "String_Node_Str"+ currentVersion);
  }
  if (Version.compare(trimmedCurrentVersion,upgrades[upgrades.length - 1].getUpgradedVersion()) != 0) {
    s_logger.error("String_Node_Str" + upgrades[upgrades.length - 1].getUpgradedVersion() + "String_Node_Str"+ currentVersion);
    throw new CloudRuntimeException("String_Node_Str" + upgrades[upgrades.length - 1].getUpgradedVersion() + "String_Node_Str"+ currentVersion);
  }
  boolean supportsRollingUpgrade=true;
  for (  DbUpgrade upgrade : upgrades) {
    if (!upgrade.supportsRollingUpgrade()) {
      supportsRollingUpgrade=false;
      break;
    }
  }
  if (!supportsRollingUpgrade && ClusterManagerImpl.arePeersRunning(null)) {
    s_logger.error("String_Node_Str");
    throw new CloudRuntimeException("String_Node_Str");
  }
  for (  DbUpgrade upgrade : upgrades) {
    s_logger.debug("String_Node_Str" + upgrade.getClass().getSimpleName() + "String_Node_Str"+ upgrade.getUpgradableVersionRange()[0]+ "String_Node_Str"+ upgrade.getUpgradableVersionRange()[1]+ "String_Node_Str"+ upgrade.getUpgradedVersion());
    Transaction txn=Transaction.open("String_Node_Str");
    txn.start();
    try {
      Connection conn;
      try {
        conn=txn.getConnection();
      }
 catch (      SQLException e) {
        s_logger.error("String_Node_Str",e);
        throw new CloudRuntimeException("String_Node_Str",e);
      }
      File[] scripts=upgrade.getPrepareScripts();
      if (scripts != null) {
        for (        File script : scripts) {
          runScript(script);
        }
      }
      upgrade.performDataMigration(conn);
      boolean upgradeVersion=true;
      if (upgrade.getUpgradedVersion().equals("String_Node_Str")) {
        upgradeVersion=false;
      }
 else       if (upgrade.getUpgradedVersion().equals("String_Node_Str")) {
        try {
          PreparedStatement pstmt=conn.prepareStatement("String_Node_Str");
          ResultSet rs=pstmt.executeQuery();
          if (rs.next()) {
            upgradeVersion=false;
          }
        }
 catch (        SQLException e) {
          throw new CloudRuntimeException("String_Node_Str",e);
        }
      }
      if (upgradeVersion) {
        VersionVO version=new VersionVO(upgrade.getUpgradedVersion());
        _dao.persist(version);
      }
      txn.commit();
    }
  finally {
      txn.close();
    }
  }
  if (!ClusterManagerImpl.arePeersRunning(trimmedCurrentVersion)) {
    s_logger.info("String_Node_Str");
    TreeMap<String,List<DbUpgrade>> upgradedVersions=new TreeMap<String,List<DbUpgrade>>();
    for (    DbUpgrade upgrade : upgrades) {
      String upgradedVerson=upgrade.getUpgradedVersion();
      List<DbUpgrade> upgradeList=upgradedVersions.get(upgradedVerson);
      if (upgradeList == null) {
        upgradeList=new ArrayList<DbUpgrade>();
      }
      upgradeList.add(upgrade);
      upgradedVersions.put(upgradedVerson,upgradeList);
    }
    for (    String upgradedVersion : upgradedVersions.keySet()) {
      List<DbUpgrade> versionUpgrades=upgradedVersions.get(upgradedVersion);
      VersionVO version=_dao.findByVersion(upgradedVersion,Step.Upgrade);
      s_logger.debug("String_Node_Str" + upgradedVersion + "String_Node_Str");
      Transaction txn=Transaction.open("String_Node_Str");
      try {
        if (version != null) {
          for (          DbUpgrade upgrade : versionUpgrades) {
            s_logger.info("String_Node_Str" + upgrade.getClass().getSimpleName() + "String_Node_Str"+ upgrade.getUpgradableVersionRange()[0]+ "String_Node_Str"+ upgrade.getUpgradableVersionRange()[1]+ "String_Node_Str"+ upgrade.getUpgradedVersion());
            txn.start();
            File[] scripts=upgrade.getCleanupScripts();
            if (scripts != null) {
              for (              File script : scripts) {
                runScript(script);
                s_logger.debug("String_Node_Str" + script.getAbsolutePath() + "String_Node_Str");
              }
            }
            txn.commit();
          }
          txn.start();
          version.setStep(Step.Complete);
          s_logger.debug("String_Node_Str" + upgradedVersion);
          version.setUpdated(new Date());
          _dao.update(version.getId(),version);
          txn.commit();
        }
      }
  finally {
        txn.close();
      }
    }
  }
}

Fixed version (ground truth):
protected void upgrade(String dbVersion,String currentVersion){
  s_logger.info("String_Node_Str" + dbVersion + "String_Node_Str"+ currentVersion);
  String trimmedDbVersion=Version.trimToPatch(dbVersion);
  String trimmedCurrentVersion=Version.trimToPatch(currentVersion);
  DbUpgrade[] upgrades=_upgradeMap.get(trimmedDbVersion);
  if (upgrades == null) {
    s_logger.error("String_Node_Str" + dbVersion + "String_Node_Str"+ currentVersion);
    throw new CloudRuntimeException("String_Node_Str" + dbVersion + "String_Node_Str"+ currentVersion);
  }
  if (Version.compare(trimmedCurrentVersion,upgrades[upgrades.length - 1].getUpgradedVersion()) != 0) {
    s_logger.error("String_Node_Str" + upgrades[upgrades.length - 1].getUpgradedVersion() + "String_Node_Str"+ currentVersion);
    throw new CloudRuntimeException("String_Node_Str" + upgrades[upgrades.length - 1].getUpgradedVersion() + "String_Node_Str"+ currentVersion);
  }
  boolean supportsRollingUpgrade=true;
  for (  DbUpgrade upgrade : upgrades) {
    if (!upgrade.supportsRollingUpgrade()) {
      supportsRollingUpgrade=false;
      break;
    }
  }
  if (!supportsRollingUpgrade && ClusterManagerImpl.arePeersRunning(null)) {
    s_logger.error("String_Node_Str");
    throw new CloudRuntimeException("String_Node_Str");
  }
  for (  DbUpgrade upgrade : upgrades) {
    s_logger.debug("String_Node_Str" + upgrade.getClass().getSimpleName() + "String_Node_Str"+ upgrade.getUpgradableVersionRange()[0]+ "String_Node_Str"+ upgrade.getUpgradableVersionRange()[1]+ "String_Node_Str"+ upgrade.getUpgradedVersion());
    Transaction txn=Transaction.open("String_Node_Str");
    txn.start();
    try {
      Connection conn;
      try {
        conn=txn.getConnection();
      }
 catch (      SQLException e) {
        s_logger.error("String_Node_Str",e);
        throw new CloudRuntimeException("String_Node_Str",e);
      }
      File[] scripts=upgrade.getPrepareScripts();
      if (scripts != null) {
        for (        File script : scripts) {
          runScript(conn,script);
        }
      }
      upgrade.performDataMigration(conn);
      boolean upgradeVersion=true;
      if (upgrade.getUpgradedVersion().equals("String_Node_Str")) {
        upgradeVersion=false;
      }
 else       if (upgrade.getUpgradedVersion().equals("String_Node_Str")) {
        try {
          PreparedStatement pstmt=conn.prepareStatement("String_Node_Str");
          ResultSet rs=pstmt.executeQuery();
          if (rs.next()) {
            upgradeVersion=false;
          }
        }
 catch (        SQLException e) {
          throw new CloudRuntimeException("String_Node_Str",e);
        }
      }
      if (upgradeVersion) {
        VersionVO version=new VersionVO(upgrade.getUpgradedVersion());
        _dao.persist(version);
      }
      txn.commit();
    }
  finally {
      txn.close();
    }
  }
  if (!ClusterManagerImpl.arePeersRunning(trimmedCurrentVersion)) {
    s_logger.info("String_Node_Str");
    TreeMap<String,List<DbUpgrade>> upgradedVersions=new TreeMap<String,List<DbUpgrade>>();
    for (    DbUpgrade upgrade : upgrades) {
      String upgradedVerson=upgrade.getUpgradedVersion();
      List<DbUpgrade> upgradeList=upgradedVersions.get(upgradedVerson);
      if (upgradeList == null) {
        upgradeList=new ArrayList<DbUpgrade>();
      }
      upgradeList.add(upgrade);
      upgradedVersions.put(upgradedVerson,upgradeList);
    }
    for (    String upgradedVersion : upgradedVersions.keySet()) {
      List<DbUpgrade> versionUpgrades=upgradedVersions.get(upgradedVersion);
      VersionVO version=_dao.findByVersion(upgradedVersion,Step.Upgrade);
      s_logger.debug("String_Node_Str" + upgradedVersion + "String_Node_Str");
      Transaction txn=Transaction.open("String_Node_Str");
      try {
        if (version != null) {
          for (          DbUpgrade upgrade : versionUpgrades) {
            s_logger.info("String_Node_Str" + upgrade.getClass().getSimpleName() + "String_Node_Str"+ upgrade.getUpgradableVersionRange()[0]+ "String_Node_Str"+ upgrade.getUpgradableVersionRange()[1]+ "String_Node_Str"+ upgrade.getUpgradedVersion());
            txn.start();
            Connection conn;
            try {
              conn=txn.getConnection();
            }
 catch (            SQLException e) {
              s_logger.error("String_Node_Str",e);
              throw new CloudRuntimeException("String_Node_Str",e);
            }
            File[] scripts=upgrade.getCleanupScripts();
            if (scripts != null) {
              for (              File script : scripts) {
                runScript(conn,script);
                s_logger.debug("String_Node_Str" + script.getAbsolutePath() + "String_Node_Str");
              }
            }
            txn.commit();
          }
          txn.start();
          version.setStep(Step.Complete);
          s_logger.debug("String_Node_Str" + upgradedVersion);
          version.setUpdated(new Date());
          _dao.update(version.getId(),version);
          txn.commit();
        }
      }
  finally {
        txn.close();
      }
    }
  }
}