Program: 105430
Project: 105430
Buggy source:
private VirtualMachineDiskInfo getMatchingExistingDisk(VirtualMachineDiskInfoBuilder diskInfoBuilder,DiskTO vol,VmwareHypervisorHost hyperHost,VmwareContext context) throws Exception {
  if (diskInfoBuilder != null) {
    VolumeObjectTO volume=(VolumeObjectTO)vol.getData();
    ManagedObjectReference morDs=HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost,volume.getDataStore().getUuid());
    DatastoreMO dsMo=new DatastoreMO(context,morDs);
    String dsName=dsMo.getName();
    Map<String,String> details=vol.getDetails();
    boolean isManaged=details != null && Boolean.parseBoolean(details.get(DiskTO.MANAGED));
    VirtualMachineDiskInfo diskInfo=diskInfoBuilder.getDiskInfoByBackingFileBaseName(isManaged ? new DatastoreFile(volume.getPath()).getFileBaseName() : volume.getPath(),dsName);
    if (diskInfo != null) {
      s_logger.info("String_Node_Str" + volume.getPath());
      return diskInfo;
    }
 else {
      String chainInfo=volume.getChainInfo();
      if (chainInfo != null) {
        VirtualMachineDiskInfo infoInChain=_gson.fromJson(chainInfo,VirtualMachineDiskInfo.class);
        if (infoInChain != null) {
          String[] disks=infoInChain.getDiskChain();
          if (disks.length > 0) {
            for (            String diskPath : disks) {
              DatastoreFile file=new DatastoreFile(diskPath);
              diskInfo=diskInfoBuilder.getDiskInfoByBackingFileBaseName(file.getFileBaseName(),dsName);
              if (diskInfo != null) {
                s_logger.info("String_Node_Str" + diskPath);
                return diskInfo;
              }
            }
          }
          if (diskInfo == null) {
            diskInfo=diskInfoBuilder.getDiskInfoByDeviceBusName(infoInChain.getDiskDeviceBusName());
            if (diskInfo != null) {
              s_logger.info("String_Node_Str" + infoInChain.getDiskDeviceBusName());
              return diskInfo;
            }
          }
        }
      }
    }
  }
  return null;
}

Fixed version (ground truth):
private VirtualMachineDiskInfo getMatchingExistingDisk(VirtualMachineDiskInfoBuilder diskInfoBuilder,DiskTO vol,VmwareHypervisorHost hyperHost,VmwareContext context) throws Exception {
  if (diskInfoBuilder != null) {
    VolumeObjectTO volume=(VolumeObjectTO)vol.getData();
    String dsName=null;
    String diskBackingFileBaseName=null;
    Map<String,String> details=vol.getDetails();
    boolean isManaged=details != null && Boolean.parseBoolean(details.get(DiskTO.MANAGED));
    if (isManaged) {
      String iScsiName=details.get(DiskTO.IQN);
      dsName=VmwareResource.getDatastoreName(iScsiName);
      diskBackingFileBaseName=new DatastoreFile(volume.getPath()).getFileBaseName();
    }
 else {
      ManagedObjectReference morDs=HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost,volume.getDataStore().getUuid());
      DatastoreMO dsMo=new DatastoreMO(context,morDs);
      dsName=dsMo.getName();
      diskBackingFileBaseName=volume.getPath();
    }
    VirtualMachineDiskInfo diskInfo=diskInfoBuilder.getDiskInfoByBackingFileBaseName(diskBackingFileBaseName,dsName);
    if (diskInfo != null) {
      s_logger.info("String_Node_Str" + volume.getPath());
      return diskInfo;
    }
 else {
      String chainInfo=volume.getChainInfo();
      if (chainInfo != null) {
        VirtualMachineDiskInfo infoInChain=_gson.fromJson(chainInfo,VirtualMachineDiskInfo.class);
        if (infoInChain != null) {
          String[] disks=infoInChain.getDiskChain();
          if (disks.length > 0) {
            for (            String diskPath : disks) {
              DatastoreFile file=new DatastoreFile(diskPath);
              diskInfo=diskInfoBuilder.getDiskInfoByBackingFileBaseName(file.getFileBaseName(),dsName);
              if (diskInfo != null) {
                s_logger.info("String_Node_Str" + diskPath);
                return diskInfo;
              }
            }
          }
          if (diskInfo == null) {
            diskInfo=diskInfoBuilder.getDiskInfoByDeviceBusName(infoInChain.getDiskDeviceBusName());
            if (diskInfo != null) {
              s_logger.info("String_Node_Str" + infoInChain.getDiskDeviceBusName());
              return diskInfo;
            }
          }
        }
      }
    }
  }
  return null;
}