Program: 4811
Project: 4811
Buggy source:
@Override public Void call(JavaRDD<T> data,Time batchTime) throws Exception {
  final long logicalStartTime=batchTime.milliseconds();
  MacroEvaluator evaluator=new DefaultMacroEvaluator(sec.getWorkflowToken(),sec.getRuntimeArguments(),logicalStartTime,sec.getSecureStore(),sec.getNamespace());
  final PluginContext pluginContext=new SparkPipelinePluginContext(sec.getPluginContext(),sec.getMetrics(),stageSpec.isStageLoggingEnabled(),stageSpec.isProcessTimingEnabled());
  final PipelineRuntime pipelineRuntime=new SparkPipelineRuntime(sec,batchTime.milliseconds());
  final String stageName=stageSpec.getName();
  final SparkSink<T> sparkSink=pluginContext.newPluginInstance(stageName,evaluator);
  boolean isPrepared=false;
  boolean isDone=false;
  try {
    sec.execute(new TxRunnable(){
      @Override public void run(      DatasetContext datasetContext) throws Exception {
        SparkPluginContext context=new BasicSparkPluginContext(null,pipelineRuntime,stageSpec,datasetContext,sec.getAdmin());
        sparkSink.prepareRun(context);
      }
    }
);
    isPrepared=true;
    final SparkExecutionPluginContext sparkExecutionPluginContext=new SparkStreamingExecutionContext(sec,JavaSparkContext.fromSparkContext(data.rdd().context()),logicalStartTime,stageSpec);
    final JavaRDD<T> countedRDD=data.map(new CountingFunction<T>(stageName,sec.getMetrics(),"String_Node_Str",null)).cache();
    sec.execute(new TxRunnable(){
      @Override public void run(      DatasetContext context) throws Exception {
        sparkSink.run(sparkExecutionPluginContext,countedRDD);
      }
    }
);
    isDone=true;
    sec.execute(new TxRunnable(){
      @Override public void run(      DatasetContext datasetContext) throws Exception {
        SparkPluginContext context=new BasicSparkPluginContext(null,pipelineRuntime,stageSpec,datasetContext,sec.getAdmin());
        sparkSink.onRunFinish(true,context);
      }
    }
);
  }
 catch (  Exception e) {
    LOG.error("String_Node_Str",stageName,logicalStartTime,e);
  }
 finally {
    if (isPrepared && !isDone) {
      sec.execute(new TxRunnable(){
        @Override public void run(        DatasetContext datasetContext) throws Exception {
          SparkPluginContext context=new BasicSparkPluginContext(null,pipelineRuntime,stageSpec,datasetContext,sec.getAdmin());
          sparkSink.onRunFinish(false,context);
        }
      }
);
    }
  }
  return null;
}

Fixed version (ground truth):
@Override public Void call(JavaRDD<T> data,Time batchTime) throws Exception {
  if (data.isEmpty()) {
    return null;
  }
  final long logicalStartTime=batchTime.milliseconds();
  MacroEvaluator evaluator=new DefaultMacroEvaluator(sec.getWorkflowToken(),sec.getRuntimeArguments(),logicalStartTime,sec.getSecureStore(),sec.getNamespace());
  final PluginContext pluginContext=new SparkPipelinePluginContext(sec.getPluginContext(),sec.getMetrics(),stageSpec.isStageLoggingEnabled(),stageSpec.isProcessTimingEnabled());
  final PipelineRuntime pipelineRuntime=new SparkPipelineRuntime(sec,batchTime.milliseconds());
  final String stageName=stageSpec.getName();
  final SparkSink<T> sparkSink=pluginContext.newPluginInstance(stageName,evaluator);
  boolean isPrepared=false;
  boolean isDone=false;
  try {
    sec.execute(new TxRunnable(){
      @Override public void run(      DatasetContext datasetContext) throws Exception {
        SparkPluginContext context=new BasicSparkPluginContext(null,pipelineRuntime,stageSpec,datasetContext,sec.getAdmin());
        sparkSink.prepareRun(context);
      }
    }
);
    isPrepared=true;
    final SparkExecutionPluginContext sparkExecutionPluginContext=new SparkStreamingExecutionContext(sec,JavaSparkContext.fromSparkContext(data.rdd().context()),logicalStartTime,stageSpec);
    final JavaRDD<T> countedRDD=data.map(new CountingFunction<T>(stageName,sec.getMetrics(),"String_Node_Str",null)).cache();
    sec.execute(new TxRunnable(){
      @Override public void run(      DatasetContext context) throws Exception {
        sparkSink.run(sparkExecutionPluginContext,countedRDD);
      }
    }
);
    isDone=true;
    sec.execute(new TxRunnable(){
      @Override public void run(      DatasetContext datasetContext) throws Exception {
        SparkPluginContext context=new BasicSparkPluginContext(null,pipelineRuntime,stageSpec,datasetContext,sec.getAdmin());
        sparkSink.onRunFinish(true,context);
      }
    }
);
  }
 catch (  Exception e) {
    LOG.error("String_Node_Str",stageName,logicalStartTime,e);
  }
 finally {
    if (isPrepared && !isDone) {
      sec.execute(new TxRunnable(){
        @Override public void run(        DatasetContext datasetContext) throws Exception {
          SparkPluginContext context=new BasicSparkPluginContext(null,pipelineRuntime,stageSpec,datasetContext,sec.getAdmin());
          sparkSink.onRunFinish(false,context);
        }
      }
);
    }
  }
  return null;
}