Program: 21549
Project: 21549
Buggy source:
private void setNodesAndParents() throws ExceptionHugin {
  List<Attribute> atts=new ArrayList<>();
  NodeList huginNodes=this.huginBN.getNodes();
  int numNodes=huginNodes.size();
  for (int i=0; i < numNodes; i++) {
    Node n=(Node)huginNodes.get(i);
    if (n.getKind().compareTo(NetworkModel.H_KIND_DISCRETE) == 0) {
      int numStates=(int)((DiscreteChanceNode)n).getNumberOfStates();
      atts.add(new Attribute(i,n.getName(),"String_Node_Str",StateSpaceType.FINITE_SET,numStates));
    }
 else     if (n.getKind().compareTo(NetworkModel.H_KIND_CONTINUOUS) == 0) {
      atts.add(new Attribute(i,n.getName(),"String_Node_Str",StateSpaceType.REAL,0));
    }
  }
  StaticVariables staticVariables=new StaticVariables(new Attributes(atts));
  DAG dag=new DAG(staticVariables);
  StaticVariables amidstVariables=staticVariables;
  for (int i=0; i < numNodes; i++) {
    Node huginChild=(Node)huginNodes.get(i);
    NodeList huginParents=huginChild.getParents();
    Variable amidstChild=amidstVariables.getVariableByName(huginChild.getName());
    for (int j=0; j < huginParents.size(); j++) {
      Node huginParent=(Node)huginParents.get(j);
      Variable amidstParent=amidstVariables.getVariableByName(huginParent.getName());
      dag.getParentSet(amidstChild).addParent(amidstParent);
    }
  }
  this.amidstBN=BayesianNetwork.newBayesianNetwork(dag);
}

Fixed version (ground truth):
private void setNodesAndParents() throws ExceptionHugin {
  List<Attribute> atts=new ArrayList<>();
  NodeList huginNodes=this.huginBN.getNodes();
  int numNodes=huginNodes.size();
  for (int i=0; i < numNodes; i++) {
    Node n=(Node)huginNodes.get(i);
    if (n.getKind().compareTo(NetworkModel.H_KIND_DISCRETE) == 0) {
      int numStates=(int)((DiscreteChanceNode)n).getNumberOfStates();
      atts.add(new Attribute(i,n.getName(),"String_Node_Str",StateSpaceType.FINITE_SET,numStates));
    }
 else     if (n.getKind().compareTo(NetworkModel.H_KIND_CONTINUOUS) == 0) {
      atts.add(new Attribute(i,n.getName(),"String_Node_Str",StateSpaceType.REAL,0));
    }
  }
  StaticVariables staticVariables=new StaticVariables(new Attributes(atts));
  DAG dag=new DAG(staticVariables);
  StaticVariables amidstVariables=staticVariables;
  for (int i=0; i < numNodes; i++) {
    Node huginChild=huginNodes.get(i);
    NodeList huginParents=huginChild.getParents();
    Variable amidstChild=amidstVariables.getVariableByName(huginChild.getName());
    ArrayList<Integer> multinomialParentsIndexes=new ArrayList();
    for (int j=0; j < huginParents.size(); j++) {
      Node huginParent=huginParents.get(j);
      if (huginParent.getKind().compareTo(NetworkModel.H_KIND_DISCRETE) == 0) {
        multinomialParentsIndexes.add(j);
      }
    }
    Collections.reverse(multinomialParentsIndexes);
    ArrayList<Integer> parentsIndexes=new ArrayList();
    for (int j=0; j < huginParents.size(); j++) {
      Node huginParent=huginParents.get(j);
      if (huginParent.getKind().compareTo(NetworkModel.H_KIND_DISCRETE) == 0) {
        parentsIndexes.add(multinomialParentsIndexes.get(0));
        multinomialParentsIndexes.remove(0);
      }
 else {
        parentsIndexes.add(j);
      }
    }
    for (int j=0; j < huginParents.size(); j++) {
      Node huginParent=huginParents.get(parentsIndexes.get(j));
      Variable amidstParent=amidstVariables.getVariableByName(huginParent.getName());
      dag.getParentSet(amidstChild).addParent(amidstParent);
    }
  }
  this.amidstBN=BayesianNetwork.newBayesianNetwork(dag);
}