Program: 67196
Project: 67196
Buggy source:
/** 
 * Process properties that define connection policy.
 */
protected ConnectionPolicy processConnectionPolicyProperties(){
  ConnectionPolicy policy=serverSession.getDefaultConnectionPolicy();
  if (properties == null || properties.isEmpty()) {
    return policy;
  }
  ConnectionPolicy policyFromProperties=(ConnectionPolicy)properties.get(EntityManagerProperties.CONNECTION_POLICY);
  if (policyFromProperties != null) {
    policy=policyFromProperties;
  }
  ConnectionPolicy newPolicy=null;
  String isLazyString=EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(EntityManagerProperties.EXCLUSIVE_CONNECTION_IS_LAZY,properties,serverSession,false);
  if (isLazyString != null) {
    boolean isLazy=Boolean.parseBoolean(isLazyString);
    if (policy.isLazy() != isLazy) {
      if (newPolicy == null) {
        newPolicy=(ConnectionPolicy)policy.clone();
      }
      newPolicy.setIsLazy(isLazy);
    }
  }
  ConnectionPolicy.ExclusiveMode exclusiveMode=EntityManagerSetupImpl.getConnectionPolicyExclusiveModeFromProperties(properties,serverSession,false);
  if (exclusiveMode != null) {
    if (!exclusiveMode.equals(policy.getExclusiveMode())) {
      if (newPolicy == null) {
        newPolicy=(ConnectionPolicy)policy.clone();
      }
      newPolicy.setExclusiveMode(exclusiveMode);
    }
  }
  String user=EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(EntityManagerProperties.JDBC_USER,properties,serverSession,false);
  String password=EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(EntityManagerProperties.JDBC_PASSWORD,properties,serverSession,false);
  String driver=EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(EntityManagerProperties.JDBC_DRIVER,properties,serverSession,false);
  String connectionString=EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(EntityManagerProperties.JDBC_URL,properties,serverSession,false);
  Object jtaDataSourceObj=EntityManagerFactoryProvider.getConfigPropertyLogDebug(EntityManagerProperties.JTA_DATASOURCE,properties,serverSession,false);
  DataSource jtaDataSource=null;
  String jtaDataSourceName=null;
  if (jtaDataSourceObj != null) {
    if (jtaDataSourceObj instanceof DataSource) {
      jtaDataSource=(DataSource)jtaDataSourceObj;
    }
 else     if (jtaDataSourceObj instanceof String) {
      jtaDataSourceName=(String)jtaDataSourceObj;
    }
  }
  Object nonjtaDataSourceObj=EntityManagerFactoryProvider.getConfigPropertyLogDebug(EntityManagerProperties.NON_JTA_DATASOURCE,properties,serverSession,false);
  DataSource nonjtaDataSource=null;
  String nonjtaDataSourceName=null;
  if (nonjtaDataSourceObj != null) {
    if (nonjtaDataSourceObj instanceof DataSource) {
      nonjtaDataSource=(DataSource)nonjtaDataSourceObj;
    }
 else     if (nonjtaDataSourceObj instanceof String) {
      nonjtaDataSourceName=(String)nonjtaDataSourceObj;
    }
  }
  if (user != null || password != null || driver != null || connectionString != null || jtaDataSourceObj != null || nonjtaDataSourceObj != null) {
    boolean isDefaultConnectorRequired=isPropertyToBeAdded(driver) || isPropertyToBeAdded(connectionString);
    boolean isJNDIConnectorRequired=isPropertyToBeAdded(jtaDataSource,jtaDataSourceName) || isPropertyToBeAdded(nonjtaDataSource,nonjtaDataSourceName);
    if (isDefaultConnectorRequired && isJNDIConnectorRequired) {
      throw new IllegalArgumentException(ExceptionLocalization.buildMessage("String_Node_Str",new Object[]{}));
    }
    DatasourceLogin login=(DatasourceLogin)policy.getLogin();
    if (login == null) {
      if (policy.getPoolName() != null) {
        login=(DatasourceLogin)serverSession.getConnectionPool(policy.getPoolName()).getLogin();
      }
 else {
        login=(DatasourceLogin)serverSession.getDatasourceLogin();
      }
    }
    if (login.shouldUseExternalTransactionController() && isDefaultConnectorRequired) {
      throw new IllegalArgumentException(ExceptionLocalization.buildMessage("String_Node_Str",new Object[]{}));
    }
    javax.sql.DataSource dataSource=null;
    String dataSourceName=null;
    if (isJNDIConnectorRequired) {
      if (login.shouldUseExternalTransactionController()) {
        if (isPropertyToBeAdded(jtaDataSource,jtaDataSourceName)) {
          dataSource=jtaDataSource;
          dataSourceName=jtaDataSourceName;
        }
        if (isPropertyToBeAdded(nonjtaDataSource,nonjtaDataSourceName)) {
          serverSession.log(SessionLog.WARNING,SessionLog.PROPERTIES,"String_Node_Str");
        }
      }
 else {
        if (isPropertyToBeAdded(nonjtaDataSource,nonjtaDataSourceName)) {
          dataSource=nonjtaDataSource;
          dataSourceName=nonjtaDataSourceName;
        }
        if (isPropertyToBeAdded(jtaDataSource,jtaDataSourceName)) {
          serverSession.log(SessionLog.WARNING,SessionLog.PROPERTIES,"String_Node_Str");
        }
      }
    }
    Boolean isNewUserRequired=isPropertyValueToBeUpdated(login.getUserName(),user);
    Boolean isNewPasswordRequired;
    if (isNewUserRequired != null && !isNewUserRequired) {
      isNewPasswordRequired=Boolean.FALSE;
    }
 else {
      isNewPasswordRequired=isPropertyValueToBeUpdated(login.getPassword(),password);
    }
    DefaultConnector oldDefaultConnector=null;
    if (login.getConnector() instanceof DefaultConnector) {
      oldDefaultConnector=(DefaultConnector)login.getConnector();
    }
    boolean isNewDefaultConnectorRequired=oldDefaultConnector == null && isDefaultConnectorRequired;
    JNDIConnector oldJNDIConnector=null;
    if (login.getConnector() instanceof JNDIConnector) {
      oldJNDIConnector=(JNDIConnector)login.getConnector();
    }
    boolean isNewJNDIConnectorRequired=oldJNDIConnector == null && isJNDIConnectorRequired;
    Boolean isNewDriverRequired=null;
    Boolean isNewConnectionStringRequired=null;
    if (isNewDefaultConnectorRequired) {
      isNewDriverRequired=isPropertyValueToBeUpdated(null,driver);
      isNewConnectionStringRequired=isPropertyValueToBeUpdated(null,connectionString);
    }
 else {
      if (oldDefaultConnector != null) {
        isNewDriverRequired=isPropertyValueToBeUpdated(oldDefaultConnector.getDriverClassName(),driver);
        isNewConnectionStringRequired=isPropertyValueToBeUpdated(oldDefaultConnector.getConnectionString(),connectionString);
      }
    }
    Boolean isNewDataSourceRequired=null;
    if (isNewJNDIConnectorRequired) {
      isNewDataSourceRequired=Boolean.TRUE;
    }
 else {
      if (oldJNDIConnector != null) {
        if (dataSource != null) {
          if (!dataSource.equals(oldJNDIConnector.getDataSource())) {
            isNewDataSourceRequired=Boolean.TRUE;
          }
        }
 else         if (dataSourceName != null) {
          if (!dataSourceName.equals(oldJNDIConnector.getName())) {
            isNewDataSourceRequired=Boolean.TRUE;
          }
        }
      }
    }
    if (isNewUserRequired != null || isNewPasswordRequired != null || isNewDriverRequired != null || isNewConnectionStringRequired != null || isNewDataSourceRequired) {
      if (newPolicy == null) {
        newPolicy=(ConnectionPolicy)policy.clone();
      }
      DatasourceLogin newLogin=(DatasourceLogin)newPolicy.getLogin();
      if (newPolicy.getLogin() == null || newPolicy.getLogin() == policy.getLogin()) {
        newLogin=(DatasourceLogin)login.clone();
        newPolicy.setLogin(newLogin);
      }
      newPolicy.setPoolName(null);
      if (isNewUserRequired != null) {
        if (isNewUserRequired) {
          newLogin.setProperty("String_Node_Str",user);
        }
 else {
          newLogin.getProperties().remove("String_Node_Str");
        }
      }
      if (isNewPasswordRequired != null) {
        if (isNewPasswordRequired) {
          newLogin.setProperty("String_Node_Str",password);
        }
 else {
          newLogin.getProperties().remove("String_Node_Str");
        }
      }
      if (isNewDefaultConnectorRequired) {
        newLogin.setConnector(new DefaultConnector());
        newLogin.setUsesExternalConnectionPooling(false);
      }
 else       if (isNewJNDIConnectorRequired) {
        newLogin.setConnector(new JNDIConnector());
        newLogin.setUsesExternalConnectionPooling(true);
      }
      if (isDefaultConnectorRequired) {
        DefaultConnector defaultConnector=(DefaultConnector)newLogin.getConnector();
        if (isNewDriverRequired != null) {
          if (isNewDriverRequired) {
            defaultConnector.setDriverClassName(driver);
          }
 else {
            defaultConnector.setDriverClassName(null);
          }
        }
        if (isNewConnectionStringRequired != null) {
          if (isNewConnectionStringRequired) {
            defaultConnector.setDatabaseURL(connectionString);
          }
 else {
            defaultConnector.setDatabaseURL(null);
          }
        }
      }
 else       if (isNewDataSourceRequired != null) {
        JNDIConnector jndiConnector=(JNDIConnector)newLogin.getConnector();
        if (isNewDataSourceRequired) {
          if (dataSource != null) {
            jndiConnector.setDataSource(dataSource);
          }
 else {
            jndiConnector.setName(dataSourceName);
          }
        }
      }
    }
  }
  if (newPolicy != null) {
    return newPolicy;
  }
 else {
    return policy;
  }
}

Fixed version (ground truth):
/** 
 * Process properties that define connection policy.
 */
protected ConnectionPolicy processConnectionPolicyProperties(){
  ConnectionPolicy policy=serverSession.getDefaultConnectionPolicy();
  if (properties == null || properties.isEmpty()) {
    return policy;
  }
  ConnectionPolicy policyFromProperties=(ConnectionPolicy)properties.get(EntityManagerProperties.CONNECTION_POLICY);
  if (policyFromProperties != null) {
    policy=policyFromProperties;
  }
  ConnectionPolicy newPolicy=null;
  String isLazyString=EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(EntityManagerProperties.EXCLUSIVE_CONNECTION_IS_LAZY,properties,serverSession,false);
  if (isLazyString != null) {
    boolean isLazy=Boolean.parseBoolean(isLazyString);
    if (policy.isLazy() != isLazy) {
      if (newPolicy == null) {
        newPolicy=(ConnectionPolicy)policy.clone();
      }
      newPolicy.setIsLazy(isLazy);
    }
  }
  ConnectionPolicy.ExclusiveMode exclusiveMode=EntityManagerSetupImpl.getConnectionPolicyExclusiveModeFromProperties(properties,serverSession,false);
  if (exclusiveMode != null) {
    if (!exclusiveMode.equals(policy.getExclusiveMode())) {
      if (newPolicy == null) {
        newPolicy=(ConnectionPolicy)policy.clone();
      }
      newPolicy.setExclusiveMode(exclusiveMode);
    }
  }
  String user=EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(EntityManagerProperties.JDBC_USER,properties,serverSession,false);
  String password=EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(EntityManagerProperties.JDBC_PASSWORD,properties,serverSession,false);
  String driver=EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(EntityManagerProperties.JDBC_DRIVER,properties,serverSession,false);
  String connectionString=EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(EntityManagerProperties.JDBC_URL,properties,serverSession,false);
  Object jtaDataSourceObj=EntityManagerFactoryProvider.getConfigPropertyLogDebug(EntityManagerProperties.JTA_DATASOURCE,properties,serverSession,false);
  DataSource jtaDataSource=null;
  String jtaDataSourceName=null;
  if (jtaDataSourceObj != null) {
    if (jtaDataSourceObj instanceof DataSource) {
      jtaDataSource=(DataSource)jtaDataSourceObj;
    }
 else     if (jtaDataSourceObj instanceof String) {
      jtaDataSourceName=(String)jtaDataSourceObj;
    }
  }
  Object nonjtaDataSourceObj=EntityManagerFactoryProvider.getConfigPropertyLogDebug(EntityManagerProperties.NON_JTA_DATASOURCE,properties,serverSession,false);
  DataSource nonjtaDataSource=null;
  String nonjtaDataSourceName=null;
  if (nonjtaDataSourceObj != null) {
    if (nonjtaDataSourceObj instanceof DataSource) {
      nonjtaDataSource=(DataSource)nonjtaDataSourceObj;
    }
 else     if (nonjtaDataSourceObj instanceof String) {
      nonjtaDataSourceName=(String)nonjtaDataSourceObj;
    }
  }
  if (user != null || password != null || driver != null || connectionString != null || jtaDataSourceObj != null || nonjtaDataSourceObj != null) {
    boolean isDefaultConnectorRequired=isPropertyToBeAdded(driver) || isPropertyToBeAdded(connectionString);
    boolean isJNDIConnectorRequired=isPropertyToBeAdded(jtaDataSource,jtaDataSourceName) || isPropertyToBeAdded(nonjtaDataSource,nonjtaDataSourceName);
    if (isDefaultConnectorRequired && isJNDIConnectorRequired) {
      throw new IllegalArgumentException(ExceptionLocalization.buildMessage("String_Node_Str",new Object[]{}));
    }
    DatasourceLogin login=(DatasourceLogin)policy.getLogin();
    if (login == null) {
      if (policy.getPoolName() != null) {
        login=(DatasourceLogin)serverSession.getConnectionPool(policy.getPoolName()).getLogin();
      }
 else {
        login=(DatasourceLogin)serverSession.getDatasourceLogin();
      }
    }
    if (login.shouldUseExternalTransactionController() && isDefaultConnectorRequired) {
      throw new IllegalArgumentException(ExceptionLocalization.buildMessage("String_Node_Str",new Object[]{}));
    }
    javax.sql.DataSource dataSource=null;
    String dataSourceName=null;
    if (isJNDIConnectorRequired) {
      if (login.shouldUseExternalTransactionController()) {
        if (isPropertyToBeAdded(jtaDataSource,jtaDataSourceName)) {
          dataSource=jtaDataSource;
          dataSourceName=jtaDataSourceName;
        }
        if (isPropertyToBeAdded(nonjtaDataSource,nonjtaDataSourceName)) {
          serverSession.log(SessionLog.WARNING,SessionLog.PROPERTIES,"String_Node_Str");
        }
      }
 else {
        if (isPropertyToBeAdded(nonjtaDataSource,nonjtaDataSourceName)) {
          dataSource=nonjtaDataSource;
          dataSourceName=nonjtaDataSourceName;
        }
        if (isPropertyToBeAdded(jtaDataSource,jtaDataSourceName)) {
          serverSession.log(SessionLog.WARNING,SessionLog.PROPERTIES,"String_Node_Str");
        }
      }
    }
    Boolean isNewUserRequired=isPropertyValueToBeUpdated(login.getUserName(),user);
    Boolean isNewPasswordRequired;
    if (isNewUserRequired != null && !isNewUserRequired) {
      isNewPasswordRequired=Boolean.FALSE;
    }
 else {
      isNewPasswordRequired=isPropertyValueToBeUpdated(login.getPassword(),password);
    }
    DefaultConnector oldDefaultConnector=null;
    if (login.getConnector() instanceof DefaultConnector) {
      oldDefaultConnector=(DefaultConnector)login.getConnector();
    }
    boolean isNewDefaultConnectorRequired=oldDefaultConnector == null && isDefaultConnectorRequired;
    JNDIConnector oldJNDIConnector=null;
    if (login.getConnector() instanceof JNDIConnector) {
      oldJNDIConnector=(JNDIConnector)login.getConnector();
    }
    boolean isNewJNDIConnectorRequired=oldJNDIConnector == null && isJNDIConnectorRequired;
    Boolean isNewDriverRequired=null;
    Boolean isNewConnectionStringRequired=null;
    if (isNewDefaultConnectorRequired) {
      isNewDriverRequired=isPropertyValueToBeUpdated(null,driver);
      isNewConnectionStringRequired=isPropertyValueToBeUpdated(null,connectionString);
    }
 else {
      if (oldDefaultConnector != null) {
        isNewDriverRequired=isPropertyValueToBeUpdated(oldDefaultConnector.getDriverClassName(),driver);
        isNewConnectionStringRequired=isPropertyValueToBeUpdated(oldDefaultConnector.getConnectionString(),connectionString);
      }
    }
    Boolean isNewDataSourceRequired=null;
    if (isNewJNDIConnectorRequired) {
      isNewDataSourceRequired=Boolean.TRUE;
    }
 else {
      if (oldJNDIConnector != null) {
        if (dataSource != null) {
          if (!dataSource.equals(oldJNDIConnector.getDataSource())) {
            isNewDataSourceRequired=Boolean.TRUE;
          }
        }
 else         if (dataSourceName != null) {
          if (!dataSourceName.equals(oldJNDIConnector.getName())) {
            isNewDataSourceRequired=Boolean.TRUE;
          }
        }
      }
    }
    if (isNewUserRequired != null || isNewPasswordRequired != null || isNewDriverRequired != null || isNewConnectionStringRequired != null || isNewDataSourceRequired != null) {
      if (newPolicy == null) {
        newPolicy=(ConnectionPolicy)policy.clone();
      }
      DatasourceLogin newLogin=(DatasourceLogin)newPolicy.getLogin();
      if (newPolicy.getLogin() == null || newPolicy.getLogin() == policy.getLogin()) {
        newLogin=(DatasourceLogin)login.clone();
        newPolicy.setLogin(newLogin);
      }
      newPolicy.setPoolName(null);
      if (isNewUserRequired != null) {
        if (isNewUserRequired) {
          newLogin.setProperty("String_Node_Str",user);
        }
 else {
          newLogin.getProperties().remove("String_Node_Str");
        }
      }
      if (isNewPasswordRequired != null) {
        if (isNewPasswordRequired) {
          newLogin.setProperty("String_Node_Str",password);
        }
 else {
          newLogin.getProperties().remove("String_Node_Str");
        }
      }
      if (isNewDefaultConnectorRequired) {
        newLogin.setConnector(new DefaultConnector());
        newLogin.setUsesExternalConnectionPooling(false);
      }
 else       if (isNewJNDIConnectorRequired) {
        newLogin.setConnector(new JNDIConnector());
        newLogin.setUsesExternalConnectionPooling(true);
      }
      if (isDefaultConnectorRequired) {
        DefaultConnector defaultConnector=(DefaultConnector)newLogin.getConnector();
        if (isNewDriverRequired != null) {
          if (isNewDriverRequired) {
            defaultConnector.setDriverClassName(driver);
          }
 else {
            defaultConnector.setDriverClassName(null);
          }
        }
        if (isNewConnectionStringRequired != null) {
          if (isNewConnectionStringRequired) {
            defaultConnector.setDatabaseURL(connectionString);
          }
 else {
            defaultConnector.setDatabaseURL(null);
          }
        }
      }
 else       if (isNewDataSourceRequired != null) {
        JNDIConnector jndiConnector=(JNDIConnector)newLogin.getConnector();
        if (isNewDataSourceRequired) {
          if (dataSource != null) {
            jndiConnector.setDataSource(dataSource);
          }
 else {
            jndiConnector.setName(dataSourceName);
          }
        }
      }
    }
  }
  if (newPolicy != null) {
    return newPolicy;
  }
 else {
    return policy;
  }
}