Program: 118496
Project: 118496
Buggy source:
/** 
 * DOC ycbai Comment method "replaceBasicOrCustomValidationRules".
 * @param connection
 * @param rulesConnection
 * @param isCustom
 * @param isOutput
 */
private void replaceBasicOrCustomValidationRules(INode graphicalNode,IConnection connection,ValidationRulesConnection rulesConnection,boolean isCustom,boolean isOutput){
  INode node=getApplicableNode(connection,isOutput);
  INode endNode=null;
  if (!checkTriggerAndDBSettings(node,rulesConnection,isOutput)) {
    return;
  }
  DataNode nodeUseValidationRule=(DataNode)node;
  endNode=nodeUseValidationRule;
  DataNode filterNode=null;
  List<IConnection> validRuleConnections;
  List<? extends IConnection> mainConnections;
  IMetadataTable rejectMetadataTable=null;
  DataConnection dataConnection=null;
  if (isOutput) {
    validRuleConnections=(List<IConnection>)nodeUseValidationRule.getIncomingConnections();
    mainConnections=nodeUseValidationRule.getIncomingConnections("String_Node_Str");
  }
 else {
    validRuleConnections=(List<IConnection>)nodeUseValidationRule.getOutgoingConnections();
    mainConnections=nodeUseValidationRule.getOutgoingConnections("String_Node_Str");
  }
  if (validRuleConnections == null || validRuleConnections.size() == 0) {
    return;
  }
  if (mainConnections != null && mainConnections.size() > 0) {
    dataConnection=(DataConnection)mainConnections.get(0);
  }
  if (dataConnection != null) {
    validRuleConnections.remove(dataConnection);
  }
  IComponent component=ComponentsFactoryProvider.getInstance().get("String_Node_Str",ComponentCategory.CATEGORY_4_DI.getName());
  String typeStr;
  if (isOutput) {
    typeStr="String_Node_Str";
  }
 else {
    typeStr="String_Node_Str";
  }
  String uniqueName=component.getName() + "String_Node_Str" + typeStr;
  if (dataConnection != null) {
    uniqueName+="String_Node_Str" + dataConnection.getName();
  }
  filterNode=new DataNode(component,uniqueName);
  filterNode.setActivate(connection.isActivate());
  filterNode.setStart(false);
  filterNode.setDesignSubjobStartNode(null);
  IMetadataTable filterNodeMetadataTable=null;
  if (dataConnection != null) {
    if (dataConnection.getMetadataTable() != null) {
      filterNodeMetadataTable=dataConnection.getMetadataTable();
    }
  }
 else {
    List<IMetadataTable> metadatas=nodeUseValidationRule.getMetadataList();
    if (metadatas != null && metadatas.size() > 0) {
      for (      IMetadataTable metadataTable : metadatas) {
        if ("String_Node_Str".equals(metadataTable.getAttachedConnector())) {
          filterNodeMetadataTable=metadataTable;
          break;
        }
      }
    }
  }
  if (filterNodeMetadataTable != null) {
    IMetadataTable newMetadata=filterNodeMetadataTable.clone();
    newMetadata.setTableName(uniqueName);
    filterNode.getMetadataList().remove(0);
    filterNode.getMetadataList().add(newMetadata);
  }
  filterNode.setSubProcessStart(false);
  filterNode.setProcess(node.getProcess());
  filterNode.setElementParameters(component.createElementParameters(filterNode));
  updateFilterParametersWithValidRuleConnection(filterNode,rulesConnection,isCustom);
  List<IConnection> outgoingConnections=new ArrayList<IConnection>();
  List<IConnection> incomingConnections=new ArrayList<IConnection>();
  filterNode.setIncomingConnections(incomingConnections);
  filterNode.setOutgoingConnections(outgoingConnections);
  addDataNode(filterNode);
  List<? extends INodeConnector> connectors=nodeUseValidationRule.getListConnector();
  INodeConnector rejectConnector=null;
  for (  INodeConnector connector : connectors) {
    if ("String_Node_Str".equals(connector.getName())) {
      rejectConnector=connector;
      break;
    }
  }
  ((List<INodeConnector>)filterNode.getListConnector()).add(rejectConnector);
  List<IMetadataTable> metadataList=nodeUseValidationRule.getMetadataList();
  for (  IMetadataTable metadataTable : metadataList) {
    if ("String_Node_Str".equals(metadataTable.getTableName()) && !filterNode.getMetadataList().contains(metadataTable)) {
      rejectMetadataTable=metadataTable;
      filterNode.getMetadataList().add(metadataTable);
      break;
    }
  }
  if (dataConnection != null) {
    if (isOutput) {
      incomingConnections.add(dataConnection);
      dataConnection.setTarget(filterNode);
    }
 else {
      outgoingConnections.add(dataConnection);
      dataConnection.setSource(filterNode);
      dataConnection.setTarget(connection.getTarget());
      dataConnection.setConnectorName("String_Node_Str");
    }
  }
  DataConnection dataConnec=new DataConnection();
  dataConnec.setActivate(connection.isActivate());
  dataConnec.setLineStyle(EConnectionType.FLOW_MAIN);
  dataConnec.setTraceConnection(connection.isTraceConnection());
  dataConnec.setTracesCondition(connection.getTracesCondition());
  dataConnec.setEnabledTraceColumns(connection.getEnabledTraceColumns());
  dataConnec.setMonitorConnection(connection.isMonitorConnection());
  if (!nodeUseValidationRule.getMetadataList().isEmpty()) {
    dataConnec.setMetadataTable(nodeUseValidationRule.getMetadataList().get(0));
  }
  if (isOutput) {
    dataConnec.setConnectorName("String_Node_Str");
    dataConnec.setName("String_Node_Str" + nodeUseValidationRule.getUniqueName());
    dataConnec.setSource(filterNode);
    dataConnec.setTarget(nodeUseValidationRule);
    outgoingConnections.add(dataConnec);
  }
 else {
    dataConnec.setConnectorName("String_Node_Str");
    dataConnec.setName("String_Node_Str" + nodeUseValidationRule.getUniqueName());
    dataConnec.setSource(nodeUseValidationRule);
    dataConnec.setTarget(filterNode);
    incomingConnections.add(dataConnec);
  }
  validRuleConnections.add(dataConnec);
  if (endNode.getOutgoingConnections("String_Node_Str") != null && endNode.getOutgoingConnections("String_Node_Str").size() == 1) {
    IConnection conn=endNode.getOutgoingConnections("String_Node_Str").get(0);
    INode targetNode=conn.getTarget();
    List<IConnection> outputconns=(List<IConnection>)endNode.getOutgoingConnections();
    List<IConnection> inputconnns=(List<IConnection>)targetNode.getIncomingConnections();
    outputconns.remove(conn);
    inputconnns.remove(conn);
    DataConnection rejectLink=new DataConnection();
    rejectLink.setActivate(connection.isActivate());
    rejectLink.setLineStyle(EConnectionType.FLOW_MAIN);
    rejectLink.setMetadataTable(rejectMetadataTable);
    rejectLink.setConnectorName("String_Node_Str");
    rejectLink.setName(conn.getName());
    rejectLink.setSource(filterNode);
    rejectLink.setTarget(targetNode);
    ((List<IConnection>)filterNode.getOutgoingConnections()).add(rejectLink);
    ((List<IConnection>)targetNode.getIncomingConnections()).add(rejectLink);
  }
}

Fixed version (ground truth):
/** 
 * DOC ycbai Comment method "replaceBasicOrCustomValidationRules".
 * @param connection
 * @param rulesConnection
 * @param isCustom
 * @param isOutput
 */
private void replaceBasicOrCustomValidationRules(INode graphicalNode,IConnection connection,ValidationRulesConnection rulesConnection,boolean isCustom,boolean isOutput){
  INode node=getApplicableNode(connection,isOutput);
  INode endNode=null;
  if (!checkTriggerAndDBSettings(node,rulesConnection,isOutput)) {
    return;
  }
  INode nodeUseValidationRule=node;
  endNode=nodeUseValidationRule;
  DataNode filterNode=null;
  List<IConnection> validRuleConnections;
  List<? extends IConnection> mainConnections;
  IMetadataTable rejectMetadataTable=null;
  DataConnection dataConnection=null;
  if (isOutput) {
    validRuleConnections=(List<IConnection>)nodeUseValidationRule.getIncomingConnections();
    mainConnections=nodeUseValidationRule.getIncomingConnections(EConnectionType.FLOW_MAIN);
  }
 else {
    validRuleConnections=(List<IConnection>)nodeUseValidationRule.getOutgoingConnections();
    mainConnections=nodeUseValidationRule.getOutgoingConnections(EConnectionType.FLOW_MAIN);
  }
  if (validRuleConnections == null || validRuleConnections.size() == 0) {
    return;
  }
  if (mainConnections != null && mainConnections.size() > 0) {
    dataConnection=(DataConnection)mainConnections.get(0);
  }
  if (dataConnection != null) {
    validRuleConnections.remove(dataConnection);
  }
  IComponent component=ComponentsFactoryProvider.getInstance().get("String_Node_Str",ComponentCategory.CATEGORY_4_DI.getName());
  String typeStr;
  if (isOutput) {
    typeStr="String_Node_Str";
  }
 else {
    typeStr="String_Node_Str";
  }
  String uniqueName=component.getName() + "String_Node_Str" + typeStr;
  if (dataConnection != null) {
    uniqueName+="String_Node_Str" + dataConnection.getName();
  }
  filterNode=new DataNode(component,uniqueName);
  filterNode.setActivate(connection.isActivate());
  filterNode.setStart(false);
  filterNode.setDesignSubjobStartNode(null);
  IMetadataTable filterNodeMetadataTable=null;
  if (dataConnection != null) {
    if (dataConnection.getMetadataTable() != null) {
      filterNodeMetadataTable=dataConnection.getMetadataTable();
    }
  }
 else {
    List<IMetadataTable> metadatas=nodeUseValidationRule.getMetadataList();
    if (metadatas != null && metadatas.size() > 0) {
      for (      IMetadataTable metadataTable : metadatas) {
        if ("String_Node_Str".equals(metadataTable.getAttachedConnector())) {
          filterNodeMetadataTable=metadataTable;
          break;
        }
      }
    }
  }
  if (filterNodeMetadataTable != null) {
    IMetadataTable newMetadata=filterNodeMetadataTable.clone();
    newMetadata.setTableName(uniqueName);
    filterNode.getMetadataList().remove(0);
    filterNode.getMetadataList().add(newMetadata);
  }
  filterNode.setSubProcessStart(false);
  filterNode.setProcess(node.getProcess());
  filterNode.setElementParameters(component.createElementParameters(filterNode));
  updateFilterParametersWithValidRuleConnection(filterNode,rulesConnection,isCustom);
  List<IConnection> outgoingConnections=new ArrayList<IConnection>();
  List<IConnection> incomingConnections=new ArrayList<IConnection>();
  filterNode.setIncomingConnections(incomingConnections);
  filterNode.setOutgoingConnections(outgoingConnections);
  addDataNode(filterNode);
  List<? extends INodeConnector> connectors=nodeUseValidationRule.getListConnector();
  INodeConnector rejectConnector=null;
  for (  INodeConnector connector : connectors) {
    if ("String_Node_Str".equals(connector.getName())) {
      rejectConnector=connector;
      break;
    }
  }
  ((List<INodeConnector>)filterNode.getListConnector()).add(rejectConnector);
  List<IMetadataTable> metadataList=nodeUseValidationRule.getMetadataList();
  for (  IMetadataTable metadataTable : metadataList) {
    if ("String_Node_Str".equals(metadataTable.getTableName()) && !filterNode.getMetadataList().contains(metadataTable)) {
      rejectMetadataTable=metadataTable;
      filterNode.getMetadataList().add(metadataTable);
      break;
    }
  }
  if (dataConnection != null) {
    if (isOutput) {
      incomingConnections.add(dataConnection);
      dataConnection.setTarget(filterNode);
    }
 else {
      outgoingConnections.add(dataConnection);
      dataConnection.setSource(filterNode);
      dataConnection.setTarget(connection.getTarget());
      dataConnection.setConnectorName("String_Node_Str");
    }
  }
  DataConnection dataConnec=new DataConnection();
  dataConnec.setActivate(connection.isActivate());
  dataConnec.setLineStyle(EConnectionType.FLOW_MAIN);
  dataConnec.setTraceConnection(connection.isTraceConnection());
  dataConnec.setTracesCondition(connection.getTracesCondition());
  dataConnec.setEnabledTraceColumns(connection.getEnabledTraceColumns());
  dataConnec.setMonitorConnection(connection.isMonitorConnection());
  if (!nodeUseValidationRule.getMetadataList().isEmpty()) {
    dataConnec.setMetadataTable(nodeUseValidationRule.getMetadataList().get(0));
  }
  if (isOutput) {
    dataConnec.setConnectorName("String_Node_Str");
    dataConnec.setName("String_Node_Str" + nodeUseValidationRule.getUniqueName());
    dataConnec.setSource(filterNode);
    dataConnec.setTarget(nodeUseValidationRule);
    outgoingConnections.add(dataConnec);
  }
 else {
    dataConnec.setConnectorName("String_Node_Str");
    dataConnec.setName("String_Node_Str" + nodeUseValidationRule.getUniqueName());
    dataConnec.setSource(nodeUseValidationRule);
    dataConnec.setTarget(filterNode);
    incomingConnections.add(dataConnec);
  }
  validRuleConnections.add(dataConnec);
  if (endNode.getOutgoingConnections("String_Node_Str") != null && endNode.getOutgoingConnections("String_Node_Str").size() == 1) {
    IConnection conn=endNode.getOutgoingConnections("String_Node_Str").get(0);
    INode targetNode=conn.getTarget();
    List<IConnection> outputconns=(List<IConnection>)endNode.getOutgoingConnections();
    List<IConnection> inputconnns=(List<IConnection>)targetNode.getIncomingConnections();
    outputconns.remove(conn);
    inputconnns.remove(conn);
    DataConnection rejectLink=new DataConnection();
    rejectLink.setActivate(connection.isActivate());
    rejectLink.setLineStyle(EConnectionType.FLOW_MAIN);
    rejectLink.setMetadataTable(rejectMetadataTable);
    rejectLink.setConnectorName("String_Node_Str");
    rejectLink.setName(conn.getName());
    rejectLink.setSource(filterNode);
    rejectLink.setTarget(targetNode);
    ((List<IConnection>)filterNode.getOutgoingConnections()).add(rejectLink);
    ((List<IConnection>)targetNode.getIncomingConnections()).add(rejectLink);
  }
}