Program: 53247
Project: 53247
Buggy source:
/** 
 * Creates RunListener that will prepare individual result for each test and store it to results list afterwards.
 */
static RunListener createSingleTestResultRunListener(final List<TestResult> results){
  return new RunListener(){
    private PrintStream originalOut, originalErr, stdOutStream, stdErrStream;
    private ByteArrayOutputStream rawStdOutBytes, rawStdErrBytes;
    private Result result;
    private RunListener resultListener;
    private final List<Failure> assumptionFailures=new ArrayList<>();
    private long startTime=System.currentTimeMillis();
    @Override public void testStarted(    Description description) throws Exception {
      originalOut=System.out;
      originalErr=System.err;
      rawStdOutBytes=new ByteArrayOutputStream();
      rawStdErrBytes=new ByteArrayOutputStream();
      stdOutStream=new PrintStream(rawStdOutBytes,true,ENCODING);
      stdErrStream=new PrintStream(rawStdErrBytes,true,ENCODING);
      System.setOut(stdOutStream);
      System.setErr(stdErrStream);
      result=new Result();
      resultListener=result.createListener();
      resultListener.testRunStarted(description);
      resultListener.testStarted(description);
    }
    @Override public void testFinished(    Description description) throws Exception {
      resultListener.testFinished(description);
      resultListener.testRunFinished(result);
      resultListener=null;
      System.setOut(originalOut);
      System.setErr(originalErr);
      stdOutStream.flush();
      stdErrStream.flush();
      int numFailures=result.getFailureCount();
      String className=description.getClassName();
      String methodName=description.getMethodName();
      if (numFailures < 0) {
        throw new IllegalStateException(String.format("String_Node_Str",className,methodName,numFailures,result.getFailures()));
      }
      Failure failure;
      ResultType type;
      if (assumptionFailures.size() > 0) {
        failure=assumptionFailures.get(0);
        type=ResultType.ASSUMPTION_VIOLATION;
      }
 else       if (numFailures == 0) {
        failure=null;
        type=ResultType.SUCCESS;
      }
 else {
        failure=result.getFailures().get(0);
        type=ResultType.FAILURE;
      }
      String stdOut=rawStdOutBytes.size() == 0 ? null : rawStdOutBytes.toString(ENCODING);
      String stdErr=rawStdErrBytes.size() == 0 ? null : rawStdErrBytes.toString(ENCODING);
      results.add(new TestResult(className,methodName,result.getRunTime(),type,failure,stdOut,stdErr));
    }
    /** 
 * The regular listener we created from the singular result, in this class, will not by default treat assumption failures as regular failures, and will not store them.  As a consequence, we store them ourselves!
 */
    @Override public void testAssumptionFailure(    Failure failure){
      assumptionFailures.add(failure);
      if (resultListener != null) {
        resultListener.testAssumptionFailure(failure);
      }
    }
    @Override public void testFailure(    Failure failure) throws Exception {
      if (resultListener == null) {
        recordUnpairedFailure(failure);
      }
 else {
        resultListener.testFailure(failure);
      }
    }
    @Override public void testIgnored(    Description description) throws Exception {
      if (resultListener != null) {
        resultListener.testIgnored(description);
      }
    }
    /** 
 * It's possible to encounter a Failure before we've started any tests (and therefore before testStarted() has been called).  The known example is a @BeforeClass that throws an exception, but there may be others. <p> Recording these unexpected failures helps us propagate failures back up to the "buck test" process.
 */
    private void recordUnpairedFailure(    Failure failure){
      long runtime=System.currentTimeMillis() - startTime;
      Description description=failure.getDescription();
      results.add(new TestResult(description.getClassName(),description.getMethodName(),runtime,ResultType.FAILURE,failure,null,null));
    }
  }
;
}

Fixed version (ground truth):
/** 
 * Creates RunListener that will prepare individual result for each test and store it to results list afterwards.
 */
static RunListener createSingleTestResultRunListener(final List<TestResult> results){
  return new RunListener(){
    private PrintStream originalOut, originalErr, stdOutStream, stdErrStream;
    private ByteArrayOutputStream rawStdOutBytes, rawStdErrBytes;
    private Result result;
    private RunListener resultListener;
    private Failure assumptionFailure;
    private long startTime=System.currentTimeMillis();
    @Override public void testStarted(    Description description) throws Exception {
      originalOut=System.out;
      originalErr=System.err;
      rawStdOutBytes=new ByteArrayOutputStream();
      rawStdErrBytes=new ByteArrayOutputStream();
      stdOutStream=new PrintStream(rawStdOutBytes,true,ENCODING);
      stdErrStream=new PrintStream(rawStdErrBytes,true,ENCODING);
      System.setOut(stdOutStream);
      System.setErr(stdErrStream);
      result=new Result();
      resultListener=result.createListener();
      resultListener.testRunStarted(description);
      resultListener.testStarted(description);
    }
    @Override public void testFinished(    Description description) throws Exception {
      resultListener.testFinished(description);
      resultListener.testRunFinished(result);
      resultListener=null;
      System.setOut(originalOut);
      System.setErr(originalErr);
      stdOutStream.flush();
      stdErrStream.flush();
      int numFailures=result.getFailureCount();
      String className=description.getClassName();
      String methodName=description.getMethodName();
      if (numFailures < 0) {
        throw new IllegalStateException(String.format("String_Node_Str",className,methodName,numFailures,result.getFailures()));
      }
      Failure failure;
      ResultType type;
      if (assumptionFailure != null) {
        failure=assumptionFailure;
        type=ResultType.ASSUMPTION_VIOLATION;
        assumptionFailure=null;
      }
 else       if (numFailures == 0) {
        failure=null;
        type=ResultType.SUCCESS;
      }
 else {
        failure=result.getFailures().get(0);
        type=ResultType.FAILURE;
      }
      String stdOut=rawStdOutBytes.size() == 0 ? null : rawStdOutBytes.toString(ENCODING);
      String stdErr=rawStdErrBytes.size() == 0 ? null : rawStdErrBytes.toString(ENCODING);
      results.add(new TestResult(className,methodName,result.getRunTime(),type,failure,stdOut,stdErr));
    }
    /** 
 * The regular listener we created from the singular result, in this class, will not by default treat assumption failures as regular failures, and will not store them.  As a consequence, we store them ourselves! We store the assumption-failure in a temporary field, which we'll make sure we clear each time we write results.
 */
    @Override public void testAssumptionFailure(    Failure failure){
      assumptionFailure=failure;
      if (resultListener != null) {
        resultListener.testAssumptionFailure(failure);
      }
    }
    @Override public void testFailure(    Failure failure) throws Exception {
      if (resultListener == null) {
        recordUnpairedFailure(failure);
      }
 else {
        resultListener.testFailure(failure);
      }
    }
    @Override public void testIgnored(    Description description) throws Exception {
      if (resultListener != null) {
        resultListener.testIgnored(description);
      }
    }
    /** 
 * It's possible to encounter a Failure before we've started any tests (and therefore before testStarted() has been called).  The known example is a @BeforeClass that throws an exception, but there may be others. <p> Recording these unexpected failures helps us propagate failures back up to the "buck test" process.
 */
    private void recordUnpairedFailure(    Failure failure){
      long runtime=System.currentTimeMillis() - startTime;
      Description description=failure.getDescription();
      results.add(new TestResult(description.getClassName(),description.getMethodName(),runtime,ResultType.FAILURE,failure,null,null));
    }
  }
;
}