Program: 42576
Project: 42576
Buggy source:
/** 
 * This method retuns a list of k-means cluster points
 * @param datasetURL   Dataset URL
 * @param features     List containing feature names
 * @param noOfClusters Number of clusters
 * @return Returns a list of cluster points
 * @throws ModelServiceException
 */
public List<ClusterPoint> getClusterPoints(String datasetURL,List<String> features,int noOfClusters) throws ModelServiceException {
  ClassLoader tccl=Thread.currentThread().getContextClassLoader();
  try {
    final List<ClusterPoint> clusterPoints=new ArrayList<ClusterPoint>();
    if (datasetURL == null || datasetURL.equals("String_Node_Str")) {
      throw new ModelServiceException("String_Node_Str");
    }
    if (features == null) {
      throw new ModelServiceException("String_Node_Str");
    }
    if (noOfClusters < 1) {
      throw new ModelServiceException("String_Node_Str");
    }
    Thread.currentThread().setContextClassLoader(JavaSparkContext.class.getClassLoader());
    sparkConf.setAppName(datasetURL);
    JavaSparkContext sc=new JavaSparkContext(sparkConf);
    JavaRDD<String> lines=sc.textFile(datasetURL);
    String headerRow=lines.take(1).get(0);
    String columnSeparator=MLModelUtils.getColumnSeparator(datasetURL);
    Pattern pattern=Pattern.compile(columnSeparator);
    final List<Integer> featureIndices=new ArrayList<Integer>();
    for (    String feature : features) {
      featureIndices.add(MLModelUtils.getFeatureIndex(feature,headerRow,columnSeparator));
    }
    JavaRDD<Vector> featureVectors=lines.filter(new HeaderFilter(headerRow)).sample(false,10000 / lines.count()).map(new LineToTokens(pattern)).filter(new MissingValuesFilter()).map(new TokensToVectors(featureIndices));
    KMeans kMeans=new KMeans();
    KMeansModel kMeansModel=kMeans.train(featureVectors,noOfClusters,100);
    List<Tuple2<Integer,Vector>> kMeansPredictions=kMeansModel.predict(featureVectors).zip(featureVectors).collect();
    for (    Tuple2<Integer,Vector> kMeansPrediction : kMeansPredictions) {
      ClusterPoint clusterPoint=new ClusterPoint();
      clusterPoint.setCluster(kMeansPrediction._1());
      clusterPoint.setFeatures(kMeansPrediction._2().toArray());
      clusterPoints.add(clusterPoint);
    }
    sc.stop();
    return clusterPoints;
  }
 catch (  ModelServiceException e) {
    throw new ModelServiceException("String_Node_Str" + e.getMessage(),e);
  }
 finally {
    Thread.currentThread().setContextClassLoader(tccl);
  }
}

Fixed version (ground truth):
/** 
 * This method retuns a list of k-means cluster points
 * @param datasetURL   Dataset URL
 * @param features     List containing feature names
 * @param noOfClusters Number of clusters
 * @return Returns a list of cluster points
 * @throws ModelServiceException
 */
public List<ClusterPoint> getClusterPoints(String datasetURL,List<String> features,int noOfClusters) throws ModelServiceException {
  ClassLoader tccl=Thread.currentThread().getContextClassLoader();
  try {
    List<ClusterPoint> clusterPoints=new ArrayList<ClusterPoint>();
    if (datasetURL == null || datasetURL.equals("String_Node_Str")) {
      throw new ModelServiceException("String_Node_Str");
    }
    if (features == null) {
      throw new ModelServiceException("String_Node_Str");
    }
    if (noOfClusters < 1) {
      throw new ModelServiceException("String_Node_Str");
    }
    Thread.currentThread().setContextClassLoader(JavaSparkContext.class.getClassLoader());
    sparkConf.setAppName(datasetURL);
    JavaSparkContext sc=new JavaSparkContext(sparkConf);
    JavaRDD<String> lines=sc.textFile(datasetURL);
    String headerRow=lines.take(1).get(0);
    String columnSeparator=MLModelUtils.getColumnSeparator(datasetURL);
    Pattern pattern=Pattern.compile(columnSeparator);
    List<Integer> featureIndices=new ArrayList<Integer>();
    for (    String feature : features) {
      featureIndices.add(MLModelUtils.getFeatureIndex(feature,headerRow,columnSeparator));
    }
    double sampleFraction=10000.0 / (lines.count() - 1);
    if (sampleFraction > 1.0) {
      sampleFraction=1.0;
    }
    JavaRDD<Vector> featureVectors=lines.filter(new HeaderFilter(headerRow)).sample(false,sampleFraction).map(new LineToTokens(pattern)).filter(new MissingValuesFilter()).map(new TokensToVectors(featureIndices));
    KMeans kMeans=new KMeans();
    KMeansModel kMeansModel=kMeans.train(featureVectors,noOfClusters,100);
    List<Tuple2<Integer,Vector>> kMeansPredictions=kMeansModel.predict(featureVectors).zip(featureVectors).collect();
    for (    Tuple2<Integer,Vector> kMeansPrediction : kMeansPredictions) {
      ClusterPoint clusterPoint=new ClusterPoint();
      clusterPoint.setCluster(kMeansPrediction._1());
      clusterPoint.setFeatures(kMeansPrediction._2().toArray());
      clusterPoints.add(clusterPoint);
    }
    sc.stop();
    return clusterPoints;
  }
 catch (  ModelServiceException e) {
    throw new ModelServiceException("String_Node_Str" + e.getMessage(),e);
  }
 finally {
    Thread.currentThread().setContextClassLoader(tccl);
  }
}