Program: 48523
Project: 48523
Buggy source:
@Override public boolean onDeleteCluster(ClusterBlueprint clusterBlueprint,ClusterReportQueue reports) throws SoftwareManagementPluginException {
  try {
    String clusterName=clusterBlueprint.getName();
    AmClusterDef clusterDef=new AmClusterDef(clusterBlueprint,null);
    if (isProvisioned(clusterName) && isClusterProvisionedByBDE(clusterDef)) {
      if (!onStopCluster(clusterBlueprint,reports)) {
        logger.error("String_Node_Str");
      }
      List<String> serviceNames=apiManager.getClusterServicesNames(clusterName);
      if (serviceNames != null && !serviceNames.isEmpty()) {
        for (        String serviceName : serviceNames) {
          apiManager.deleteService(clusterName,serviceName);
        }
      }
      if (apiManager.getHostsSummaryInfo(clusterName) != null) {
        List<ApiHost> hosts=apiManager.getHostsSummaryInfo(clusterName).getApiHosts();
        if (hosts != null && !hosts.isEmpty()) {
          for (          ApiHost host : hosts) {
            assert(host.getApiHostInfo() != null);
            String hostName=host.getApiHostInfo().getHostName();
            apiManager.deleteHost(clusterName,hostName);
          }
        }
      }
      apiManager.deleteCluster(clusterName);
    }
    if (isBlueprintCreated(clusterDef) && isBlueprintCreatedByBDE(clusterDef)) {
      apiManager.deleteBlueprint(clusterName);
    }
    ApiPersist persist=new ApiPersist("String_Node_Str");
    apiManager.updatePersist(persist);
    return true;
  }
 catch (  Exception e) {
    logger.error("String_Node_Str",e);
    throw SoftwareManagementPluginException.DELETE_CLUSTER_FAILED(e,AMBARI,clusterBlueprint.getName());
  }
}

Fixed version (ground truth):
@Override public boolean onDeleteCluster(ClusterBlueprint clusterBlueprint,ClusterReportQueue reports) throws SoftwareManagementPluginException {
  try {
    String clusterName=clusterBlueprint.getName();
    if (!isProvisioned(clusterName)) {
      return true;
    }
    AmClusterDef clusterDef=new AmClusterDef(clusterBlueprint,null);
    if (!isClusterProvisionedByBDE(clusterDef)) {
      return true;
    }
    if (!onStopCluster(clusterBlueprint,reports)) {
      logger.error("String_Node_Str");
    }
    List<String> serviceNames=apiManager.getClusterServicesNames(clusterName);
    if (serviceNames != null && !serviceNames.isEmpty()) {
      for (      String serviceName : serviceNames) {
        apiManager.deleteService(clusterName,serviceName);
      }
    }
    if (apiManager.getHostsSummaryInfo(clusterName) != null) {
      List<ApiHost> hosts=apiManager.getHostsSummaryInfo(clusterName).getApiHosts();
      if (hosts != null && !hosts.isEmpty()) {
        for (        ApiHost host : hosts) {
          assert(host.getApiHostInfo() != null);
          String hostName=host.getApiHostInfo().getHostName();
          apiManager.deleteHost(clusterName,hostName);
        }
      }
    }
    apiManager.deleteCluster(clusterName);
    if (isBlueprintCreated(clusterDef) && isBlueprintCreatedByBDE(clusterDef)) {
      apiManager.deleteBlueprint(clusterName);
    }
    ApiPersist persist=new ApiPersist("String_Node_Str");
    apiManager.updatePersist(persist);
    return true;
  }
 catch (  Exception e) {
    logger.error("String_Node_Str",e);
    throw SoftwareManagementPluginException.DELETE_CLUSTER_FAILED(e,AMBARI,clusterBlueprint.getName());
  }
}