Program: 30288
Project: 30288
Buggy source:
/** 
 * @param serviceConsumer   Service that consumes the service provided by serviceProvider referred via service-reference
 * @param serviceProvider   Provisioned service like DB service or JMS service.
 * @param svcRef           Service Reference from GlassFish to that service.
 * @param beforeDeployment indicates if this association is happening before the
 */
public void associateServices(ProvisionedService serviceConsumer,ServiceReference svcRef,ProvisionedService serviceProvider,boolean beforeDeployment,DeploymentContext dc){
  if (svcRef.getServiceRefType().equals("String_Node_Str") && serviceProvider.getServiceType().toString().equals("String_Node_Str")) {
    if (!beforeDeployment)     return;
    ServiceDescription serviceDescription=serviceProvider.getServiceDescription();
    Properties dbProperties=new Properties();
    dbProperties.putAll(svcRef.getProperties());
    String serverName=serviceProvider.getServiceProperties().getProperty("String_Node_Str");
    String url=serviceProvider.getServiceProperties().getProperty("String_Node_Str");
    if (serverName != null) {
      dbProperties.setProperty("String_Node_Str",serverName);
    }
    if (url != null) {
      dbProperties.setProperty("String_Node_Str",url);
    }
    String serviceName=serviceConsumer.getServiceDescription().getName();
    String clusterName=gfServiceUtil.getClusterName(serviceName,serviceDescription.getAppName());
    String dasIPAddress=gfServiceUtil.getDASIPAddress(serviceConsumer.getServiceDescription().getName());
    String poolName=svcRef.getServiceRefName();
    String resourceName=svcRef.getServiceRefName();
    GlassFishProvisioner glassFishProvisioner=(GlassFishProvisioner)provisionerUtil.getAppServerProvisioner(dasIPAddress);
    glassFishProvisioner.createJdbcConnectionPool(dasIPAddress,clusterName,dbProperties,poolName);
    glassFishProvisioner.createJdbcResource(dasIPAddress,clusterName,poolName,resourceName);
  }
  if (svcRef.getServiceRefType().equals("String_Node_Str")) {
    String appServerServiceName=serviceConsumer.getServiceDescription().getName();
    String clusterName=gfServiceUtil.getClusterName(appServerServiceName,serviceConsumer.getServiceDescription().getAppName());
    String dasIPAddress=gfServiceUtil.getDASIPAddress(serviceConsumer.getServiceDescription().getName());
    ApplicationServerProvisioner appServerProvisioner=provisionerUtil.getAppServerProvisioner(dasIPAddress);
    String lbServiceName=serviceProvider.getServiceDescription().getName();
    String domainName=domain.getProperty(Domain.DOMAIN_NAME_PROPERTY).getValue();
    if (beforeDeployment) {
      LBProvisioner lbProvisioner=provisionerUtil.getLBProvisioner();
      String lbIPAddress=gfServiceUtil.getIPAddress(lbServiceName,serviceConsumer.getServiceDescription().getAppName(),ServiceType.LOAD_BALANCER);
      lbProvisioner.associateApplicationServerWithLB(lbIPAddress,dasIPAddress,domainName);
      lbProvisioner.stopLB(lbIPAddress);
      lbProvisioner.startLB(lbIPAddress);
      appServerProvisioner.associateLBWithApplicationServer(dasIPAddress,clusterName,lbIPAddress,lbServiceName);
    }
 else {
      appServerProvisioner.refreshLBConfiguration(dasIPAddress,lbServiceName);
    }
  }
  if (beforeDeployment) {
    GlassFishProvisionedService gfps=(GlassFishProvisionedService)serviceConsumer;
    String clusterServiceName=gfServiceUtil.getClusterName(serviceConsumer.getName(),gfps.getServiceDescription().getAppName());
    if (dc != null) {
      DeployCommandParameters ucp=dc.getCommandParameters(DeployCommandParameters.class);
      ucp.target=clusterServiceName;
    }
  }
}

Fixed version (ground truth):
/** 
 * @param serviceConsumer   Service that consumes the service provided by serviceProvider referred via service-reference
 * @param serviceProvider   Provisioned service like DB service or JMS service.
 * @param svcRef           Service Reference from GlassFish to that service.
 * @param beforeDeployment indicates if this association is happening before the
 */
public void associateServices(ProvisionedService serviceConsumer,ServiceReference svcRef,ProvisionedService serviceProvider,boolean beforeDeployment,DeploymentContext dc){
  if (svcRef.getServiceRefType().equals("String_Node_Str") && serviceProvider.getServiceType().toString().equals("String_Node_Str") && serviceConsumer.getServiceType().toString().equals("String_Node_Str")) {
    if (!beforeDeployment)     return;
    ServiceDescription serviceDescription=serviceProvider.getServiceDescription();
    Properties dbProperties=new Properties();
    dbProperties.putAll(svcRef.getProperties());
    String serverName=serviceProvider.getServiceProperties().getProperty("String_Node_Str");
    String url=serviceProvider.getServiceProperties().getProperty("String_Node_Str");
    if (serverName != null) {
      dbProperties.setProperty("String_Node_Str",serverName);
    }
    if (url != null) {
      dbProperties.setProperty("String_Node_Str",url);
    }
    String serviceName=serviceConsumer.getServiceDescription().getName();
    String clusterName=gfServiceUtil.getClusterName(serviceName,serviceDescription.getAppName());
    String dasIPAddress=gfServiceUtil.getDASIPAddress(serviceConsumer.getServiceDescription().getName());
    String poolName=svcRef.getServiceRefName();
    String resourceName=svcRef.getServiceRefName();
    GlassFishProvisioner glassFishProvisioner=(GlassFishProvisioner)provisionerUtil.getAppServerProvisioner(dasIPAddress);
    glassFishProvisioner.createJdbcConnectionPool(dasIPAddress,clusterName,dbProperties,poolName);
    glassFishProvisioner.createJdbcResource(dasIPAddress,clusterName,poolName,resourceName);
  }
  if (svcRef.getServiceRefType().equals("String_Node_Str")) {
    String appServerServiceName=serviceConsumer.getServiceDescription().getName();
    String clusterName=gfServiceUtil.getClusterName(appServerServiceName,serviceConsumer.getServiceDescription().getAppName());
    String dasIPAddress=gfServiceUtil.getDASIPAddress(serviceConsumer.getServiceDescription().getName());
    ApplicationServerProvisioner appServerProvisioner=provisionerUtil.getAppServerProvisioner(dasIPAddress);
    String lbServiceName=serviceProvider.getServiceDescription().getName();
    String domainName=domain.getProperty(Domain.DOMAIN_NAME_PROPERTY).getValue();
    if (beforeDeployment) {
      LBProvisioner lbProvisioner=provisionerUtil.getLBProvisioner();
      String lbIPAddress=gfServiceUtil.getIPAddress(lbServiceName,serviceConsumer.getServiceDescription().getAppName(),ServiceType.LOAD_BALANCER);
      lbProvisioner.associateApplicationServerWithLB(lbIPAddress,dasIPAddress,domainName);
      lbProvisioner.stopLB(lbIPAddress);
      lbProvisioner.startLB(lbIPAddress);
      appServerProvisioner.associateLBWithApplicationServer(dasIPAddress,clusterName,lbIPAddress,lbServiceName);
    }
 else {
      appServerProvisioner.refreshLBConfiguration(dasIPAddress,lbServiceName);
    }
  }
  if (beforeDeployment) {
    GlassFishProvisionedService gfps=(GlassFishProvisionedService)serviceConsumer;
    String clusterServiceName=gfServiceUtil.getClusterName(serviceConsumer.getName(),gfps.getServiceDescription().getAppName());
    if (dc != null) {
      DeployCommandParameters ucp=dc.getCommandParameters(DeployCommandParameters.class);
      ucp.target=clusterServiceName;
    }
  }
}