Program: 53242
Project: 53242
Buggy source:
/** 
 * Executes the specified process.
 * @param process The {@code Process} to execute.
 * @param shouldPrintStdOut If {@code true}, then the stdout of the process will be written directly to the stdout passed to the constructor of this executor. If   {@code false}, then the stdout of the process will be made available via   {@link Result#getStdout()}.
 * @param shouldPrintStdErr If {@code true}, then the stderr of the process will be written directly to the stderr passed to the constructor of this executor. If   {@code false}, then the stderr of the process will be made available via   {@link Result#getStderr()}.
 */
public Result execute(Process process,boolean shouldPrintStdOut,boolean shouldPrintStdErr,boolean isSilent,Optional<String> stdin) throws InterruptedException {
  @SuppressWarnings("String_Node_Str") PrintStream stdOutToWriteTo=shouldPrintStdOut ? stdOutStream : new CapturingPrintStream();
  InputStreamConsumer stdOut=new InputStreamConsumer(process.getInputStream(),stdOutToWriteTo,ansi);
  @SuppressWarnings("String_Node_Str") PrintStream stdErrToWriteTo=shouldPrintStdErr ? stdErrStream : new CapturingPrintStream();
  InputStreamConsumer stdErr=new InputStreamConsumer(process.getErrorStream(),stdErrToWriteTo,ansi);
  Thread stdOutConsumer=Threads.namedThread("String_Node_Str",stdOut);
  stdOutConsumer.start();
  Thread stdErrConsumer=Threads.namedThread("String_Node_Str",stdErr);
  stdErrConsumer.start();
  try {
    if (stdin.isPresent()) {
      try (OutputStreamWriter stdinWriter=new OutputStreamWriter(process.getOutputStream())){
        stdinWriter.write(stdin.get());
      }
     }
    process.waitFor();
    stdOutConsumer.join();
    stdErrConsumer.join();
  }
 catch (  IOException e) {
    return new Result(1,null,null);
  }
 finally {
    process.destroy();
    process.waitFor();
  }
  String stdoutText=getDataIfNotPrinted(stdOutToWriteTo,shouldPrintStdOut);
  String stderrText=getDataIfNotPrinted(stdErrToWriteTo,shouldPrintStdErr);
  int exitCode=process.exitValue();
  if (exitCode != 0 && !isSilent) {
    if (!shouldPrintStdOut) {
      stdOutStream.print(stdoutText);
    }
    if (!shouldPrintStdErr) {
      stdErrStream.print(stderrText);
    }
  }
  return new Result(exitCode,stdoutText,stderrText);
}

Fixed version (ground truth):
/** 
 * Executes the specified process. <p> If   {@code options} contains {@link Option#PRINT_STD_OUT}, then the stdout of the process will be written directly to the stdout passed to the constructor of this executor. Otherwise, the stdout of the process will be made available via   {@link Result#getStdout()}. <p> If   {@code options} contains {@link Option#PRINT_STD_ERR}, then the stderr of the process will be written directly to the stderr passed to the constructor of this executor. Otherwise, the stderr of the process will be made available via   {@link Result#getStderr()}.
 */
public Result execute(Process process,Set<Option> options,Optional<String> stdin) throws InterruptedException {
  boolean shouldPrintStdOut=options.contains(Option.PRINT_STD_OUT);
  @SuppressWarnings("String_Node_Str") PrintStream stdOutToWriteTo=shouldPrintStdOut ? stdOutStream : new CapturingPrintStream();
  InputStreamConsumer stdOut=new InputStreamConsumer(process.getInputStream(),stdOutToWriteTo,ansi,!shouldPrintStdOut);
  boolean shouldPrintStdErr=options.contains(Option.PRINT_STD_ERR);
  @SuppressWarnings("String_Node_Str") PrintStream stdErrToWriteTo=shouldPrintStdErr ? stdErrStream : new CapturingPrintStream();
  InputStreamConsumer stdErr=new InputStreamConsumer(process.getErrorStream(),stdErrToWriteTo,ansi,!shouldPrintStdErr);
  Thread stdOutConsumer=Threads.namedThread("String_Node_Str",stdOut);
  stdOutConsumer.start();
  Thread stdErrConsumer=Threads.namedThread("String_Node_Str",stdErr);
  stdErrConsumer.start();
  try {
    if (stdin.isPresent()) {
      try (OutputStreamWriter stdinWriter=new OutputStreamWriter(process.getOutputStream())){
        stdinWriter.write(stdin.get());
      }
     }
    process.waitFor();
    stdOutConsumer.join();
    stdErrConsumer.join();
  }
 catch (  IOException e) {
    return new Result(1,null,null);
  }
 finally {
    process.destroy();
    process.waitFor();
  }
  String stdoutText=getDataIfNotPrinted(stdOutToWriteTo,shouldPrintStdOut);
  String stderrText=getDataIfNotPrinted(stdErrToWriteTo,shouldPrintStdErr);
  int exitCode=process.exitValue();
  if (exitCode != 0 && !options.contains(Option.IS_SILENT)) {
    if (!shouldPrintStdOut) {
      stdOutStream.print(stdoutText);
    }
    if (!shouldPrintStdErr) {
      stdErrStream.print(stderrText);
    }
  }
  return new Result(exitCode,stdoutText,stderrText);
}