Program: 162795
Project: 162795
Buggy source:
private TreeModel toTreeModel(DecisionTreeModel dtModel,CategoricalValueEncodings categoricalValueEncodings,Map<Integer,Long> nodeIDCounts){
  boolean classificationTask=dtModel.algo().equals(Algo.Classification());
  Preconditions.checkState(classificationTask == inputSchema.isClassification());
  Map<Integer,String> targetEncodingToValue=categoricalValueEncodings.getEncodingValueMap(inputSchema.getTargetFeatureIndex());
  Node root=new Node();
  root.setId("String_Node_Str");
  Queue<Node> modelNodes=new ArrayDeque<>();
  modelNodes.add(root);
  Queue<Pair<org.apache.spark.mllib.tree.model.Node,Split>> treeNodes=new ArrayDeque<>();
  treeNodes.add(new Pair<>(dtModel.topNode(),(Split)null));
  while (!treeNodes.isEmpty()) {
    Pair<org.apache.spark.mllib.tree.model.Node,Split> treeNodePredicate=treeNodes.remove();
    Node modelNode=modelNodes.remove();
    Predicate predicate=buildPredicate(treeNodePredicate.getSecond(),categoricalValueEncodings);
    modelNode.setPredicate(predicate);
    org.apache.spark.mllib.tree.model.Node treeNode=treeNodePredicate.getFirst();
    long nodeCount=nodeIDCounts.get(treeNode.id());
    modelNode.setRecordCount((double)nodeCount);
    if (treeNode.isLeaf()) {
      Predict prediction=treeNode.predict();
      int targetEncodedValue=(int)prediction.predict();
      if (classificationTask) {
        String predictedCategoricalValue=targetEncodingToValue.get(targetEncodedValue);
        double confidence=prediction.prob();
        Preconditions.checkState(confidence >= 0.0 && confidence <= 1.0);
        long pseudoSDRecordCount=Math.round(confidence * nodeCount);
        ScoreDistribution distribution=new ScoreDistribution(predictedCategoricalValue,pseudoSDRecordCount);
        distribution.setConfidence(confidence);
        modelNode.getScoreDistributions().add(distribution);
      }
 else {
        modelNode.setScore(Double.toString(targetEncodedValue));
      }
    }
 else {
      Split split=treeNode.split().get();
      Node positiveModelNode=new Node();
      positiveModelNode.setId(modelNode.getId() + '+');
      modelNode.getNodes().add(positiveModelNode);
      Node negativeModelNode=new Node();
      negativeModelNode.setId(modelNode.getId() + '-');
      modelNode.getNodes().add(negativeModelNode);
      org.apache.spark.mllib.tree.model.Node rightTreeNode=treeNode.rightNode().get();
      org.apache.spark.mllib.tree.model.Node leftTreeNode=treeNode.leftNode().get();
      boolean defaultRight=nodeIDCounts.get(rightTreeNode.id()) > nodeIDCounts.get(leftTreeNode.id());
      modelNode.setDefaultChild(defaultRight ? positiveModelNode.getId() : negativeModelNode.getId());
      modelNodes.add(positiveModelNode);
      modelNodes.add(negativeModelNode);
      treeNodes.add(new Pair<>(rightTreeNode,split));
      treeNodes.add(new Pair<>(leftTreeNode,(Split)null));
    }
  }
  TreeModel treeModel=new TreeModel();
  treeModel.setNode(root);
  treeModel.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);
  treeModel.setMissingValueStrategy(MissingValueStrategyType.DEFAULT_CHILD);
  return treeModel;
}

Fixed version (ground truth):
private TreeModel toTreeModel(DecisionTreeModel dtModel,CategoricalValueEncodings categoricalValueEncodings,Map<Integer,Long> nodeIDCounts){
  boolean classificationTask=dtModel.algo().equals(Algo.Classification());
  Preconditions.checkState(classificationTask == inputSchema.isClassification());
  Node root=new Node();
  root.setId("String_Node_Str");
  Queue<Node> modelNodes=new ArrayDeque<>();
  modelNodes.add(root);
  Queue<Pair<org.apache.spark.mllib.tree.model.Node,Split>> treeNodes=new ArrayDeque<>();
  treeNodes.add(new Pair<>(dtModel.topNode(),(Split)null));
  while (!treeNodes.isEmpty()) {
    Pair<org.apache.spark.mllib.tree.model.Node,Split> treeNodePredicate=treeNodes.remove();
    Node modelNode=modelNodes.remove();
    Predicate predicate=buildPredicate(treeNodePredicate.getSecond(),categoricalValueEncodings);
    modelNode.setPredicate(predicate);
    org.apache.spark.mllib.tree.model.Node treeNode=treeNodePredicate.getFirst();
    long nodeCount=nodeIDCounts.get(treeNode.id());
    modelNode.setRecordCount((double)nodeCount);
    if (treeNode.isLeaf()) {
      Predict prediction=treeNode.predict();
      int targetEncodedValue=(int)prediction.predict();
      if (classificationTask) {
        Map<Integer,String> targetEncodingToValue=categoricalValueEncodings.getEncodingValueMap(inputSchema.getTargetFeatureIndex());
        String predictedCategoricalValue=targetEncodingToValue.get(targetEncodedValue);
        double confidence=prediction.prob();
        Preconditions.checkState(confidence >= 0.0 && confidence <= 1.0);
        long pseudoSDRecordCount=Math.round(confidence * nodeCount);
        ScoreDistribution distribution=new ScoreDistribution(predictedCategoricalValue,pseudoSDRecordCount);
        distribution.setConfidence(confidence);
        modelNode.getScoreDistributions().add(distribution);
      }
 else {
        modelNode.setScore(Double.toString(targetEncodedValue));
      }
    }
 else {
      Split split=treeNode.split().get();
      Node positiveModelNode=new Node();
      positiveModelNode.setId(modelNode.getId() + '+');
      modelNode.getNodes().add(positiveModelNode);
      Node negativeModelNode=new Node();
      negativeModelNode.setId(modelNode.getId() + '-');
      modelNode.getNodes().add(negativeModelNode);
      org.apache.spark.mllib.tree.model.Node rightTreeNode=treeNode.rightNode().get();
      org.apache.spark.mllib.tree.model.Node leftTreeNode=treeNode.leftNode().get();
      boolean defaultRight=nodeIDCounts.get(rightTreeNode.id()) > nodeIDCounts.get(leftTreeNode.id());
      modelNode.setDefaultChild(defaultRight ? positiveModelNode.getId() : negativeModelNode.getId());
      modelNodes.add(positiveModelNode);
      modelNodes.add(negativeModelNode);
      treeNodes.add(new Pair<>(rightTreeNode,split));
      treeNodes.add(new Pair<>(leftTreeNode,(Split)null));
    }
  }
  TreeModel treeModel=new TreeModel();
  treeModel.setNode(root);
  treeModel.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);
  treeModel.setMissingValueStrategy(MissingValueStrategyType.DEFAULT_CHILD);
  return treeModel;
}