Program: 106717
Project: 106717
Buggy source:
public static synchronized Pair<ManagedObjectReference,String> preparePublicNetwork(String vSwitchName,HostMO hostMo,String vlanId,Integer networkRateMbps,Integer networkRateMulticastMbps,long timeOutMs,boolean syncPeerHosts) throws Exception {
  HostVirtualSwitch vSwitch=hostMo.getHostVirtualSwitchByName(vSwitchName);
  if (vSwitch == null) {
    String msg="String_Node_Str";
    s_logger.error(msg);
    throw new Exception(msg);
  }
  boolean createGCTag=false;
  String networkName;
  Integer vid=null;
  if (vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
    createGCTag=true;
    vid=Integer.parseInt(vlanId);
  }
  networkName=composeCloudNetworkName("String_Node_Str",vlanId,networkRateMbps,vSwitchName);
  HostNetworkTrafficShapingPolicy shapingPolicy=null;
  if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
    shapingPolicy=new HostNetworkTrafficShapingPolicy();
    shapingPolicy.setEnabled(true);
    shapingPolicy.setAverageBandwidth((long)networkRateMbps.intValue() * 1024L * 1024L);
    shapingPolicy.setPeakBandwidth((long)(shapingPolicy.getAverageBandwidth() * 1.5));
    shapingPolicy.setBurstSize(5 * shapingPolicy.getAverageBandwidth() / 8);
  }
  if (!hostMo.hasPortGroup(vSwitch,networkName)) {
    hostMo.createPortGroup(vSwitch,networkName,vid,shapingPolicy);
  }
 else {
    hostMo.updatePortGroup(vSwitch,networkName,vid,shapingPolicy);
  }
  ManagedObjectReference morNetwork=waitForNetworkReady(hostMo,networkName,timeOutMs);
  if (morNetwork == null) {
    String msg="String_Node_Str" + vSwitchName;
    s_logger.error(msg);
    throw new Exception(msg);
  }
  if (createGCTag) {
    NetworkMO networkMo=new NetworkMO(hostMo.getContext(),morNetwork);
    networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC,"String_Node_Str");
  }
  if (syncPeerHosts) {
    ManagedObjectReference morParent=hostMo.getParentMor();
    if (morParent != null && morParent.getType().equals("String_Node_Str")) {
      GlobalLock lock=GlobalLock.getInternLock("String_Node_Str" + morParent.get_value());
      try {
        if (lock.lock(DEFAULT_LOCK_TIMEOUT_SECONDS)) {
          try {
            ManagedObjectReference[] hosts=(ManagedObjectReference[])hostMo.getContext().getServiceUtil().getDynamicProperty(morParent,"String_Node_Str");
            if (hosts != null) {
              for (              ManagedObjectReference otherHost : hosts) {
                if (!otherHost.get_value().equals(hostMo.getMor().get_value())) {
                  HostMO otherHostMo=new HostMO(hostMo.getContext(),otherHost);
                  try {
                    if (s_logger.isDebugEnabled())                     s_logger.debug("String_Node_Str" + vlanId + "String_Node_Str"+ otherHostMo.getHostName());
                    preparePublicNetwork(vSwitchName,otherHostMo,vlanId,networkRateMbps,networkRateMulticastMbps,timeOutMs,false);
                  }
 catch (                  Exception e) {
                    s_logger.warn("String_Node_Str" + vlanId + "String_Node_Str"+ otherHostMo.getHostName());
                  }
                }
              }
            }
          }
  finally {
            lock.unlock();
          }
        }
 else {
          s_logger.warn("String_Node_Str" + vlanId);
        }
      }
  finally {
        lock.releaseRef();
      }
    }
  }
  s_logger.info("String_Node_Str" + networkName + "String_Node_Str"+ vSwitchName);
  return new Pair<ManagedObjectReference,String>(morNetwork,networkName);
}

Fixed version (ground truth):
public static synchronized Pair<ManagedObjectReference,String> preparePublicNetwork(String vSwitchName,HostMO hostMo,String vlanId,Integer networkRateMbps,Integer networkRateMulticastMbps,long timeOutMs,boolean syncPeerHosts) throws Exception {
  HostVirtualSwitch vSwitch=hostMo.getHostVirtualSwitchByName(vSwitchName);
  if (vSwitch == null) {
    String msg="String_Node_Str";
    s_logger.error(msg);
    throw new Exception(msg);
  }
  boolean createGCTag=false;
  String networkName;
  Integer vid=null;
  if (vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
    createGCTag=true;
    vid=Integer.parseInt(vlanId);
  }
  networkName=composeCloudNetworkName("String_Node_Str",vlanId,networkRateMbps,vSwitchName);
  HostNetworkTrafficShapingPolicy shapingPolicy=null;
  if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
    shapingPolicy=new HostNetworkTrafficShapingPolicy();
    shapingPolicy.setEnabled(true);
    shapingPolicy.setAverageBandwidth((long)networkRateMbps.intValue() * 1024L * 1024L);
    shapingPolicy.setPeakBandwidth((long)(shapingPolicy.getAverageBandwidth() * 1.5));
    shapingPolicy.setBurstSize(5 * shapingPolicy.getAverageBandwidth() / 8);
  }
  boolean bWaitPortGroupReady=false;
  if (!hostMo.hasPortGroup(vSwitch,networkName)) {
    hostMo.createPortGroup(vSwitch,networkName,vid,shapingPolicy);
    bWaitPortGroupReady=true;
  }
 else {
    HostPortGroupSpec spec=hostMo.getPortGroupSpec(networkName);
    if (!isSpecMatch(spec,vid,shapingPolicy)) {
      hostMo.updatePortGroup(vSwitch,networkName,vid,shapingPolicy);
      bWaitPortGroupReady=true;
    }
  }
  ManagedObjectReference morNetwork;
  if (bWaitPortGroupReady)   morNetwork=waitForNetworkReady(hostMo,networkName,timeOutMs);
 else   morNetwork=hostMo.getNetworkMor(networkName);
  if (morNetwork == null) {
    String msg="String_Node_Str" + vSwitchName;
    s_logger.error(msg);
    throw new Exception(msg);
  }
  if (createGCTag) {
    NetworkMO networkMo=new NetworkMO(hostMo.getContext(),morNetwork);
    networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC,"String_Node_Str");
  }
  if (syncPeerHosts) {
    ManagedObjectReference morParent=hostMo.getParentMor();
    if (morParent != null && morParent.getType().equals("String_Node_Str")) {
      GlobalLock lock=GlobalLock.getInternLock("String_Node_Str" + morParent.get_value());
      try {
        if (lock.lock(DEFAULT_LOCK_TIMEOUT_SECONDS)) {
          try {
            ManagedObjectReference[] hosts=(ManagedObjectReference[])hostMo.getContext().getServiceUtil().getDynamicProperty(morParent,"String_Node_Str");
            if (hosts != null) {
              for (              ManagedObjectReference otherHost : hosts) {
                if (!otherHost.get_value().equals(hostMo.getMor().get_value())) {
                  HostMO otherHostMo=new HostMO(hostMo.getContext(),otherHost);
                  try {
                    if (s_logger.isDebugEnabled())                     s_logger.debug("String_Node_Str" + vlanId + "String_Node_Str"+ otherHostMo.getHostName());
                    preparePublicNetwork(vSwitchName,otherHostMo,vlanId,networkRateMbps,networkRateMulticastMbps,timeOutMs,false);
                  }
 catch (                  Exception e) {
                    s_logger.warn("String_Node_Str" + vlanId + "String_Node_Str"+ otherHostMo.getHostName());
                  }
                }
              }
            }
          }
  finally {
            lock.unlock();
          }
        }
 else {
          s_logger.warn("String_Node_Str" + vlanId);
        }
      }
  finally {
        lock.releaseRef();
      }
    }
  }
  s_logger.info("String_Node_Str" + networkName + "String_Node_Str"+ vSwitchName);
  return new Pair<ManagedObjectReference,String>(morNetwork,networkName);
}