Source:
protected static String readPipe(File dir, String[] command, String encoding, Map<String, String> env) throws CommandFailedException { final boolean debug = LOG.isDebugEnabled(); try { if (debug) { LOG.debug("readpipe " + Arrays.asList(command) + "," + dir); } ProcessBuilder pb = new ProcessBuilder(command); pb.directory(dir); if (env != null) { pb.environment().putAll(env); } Process p; try { p = pb.start(); } catch (IOException e) { throw new CommandFailedException(-1, e.getMessage(), e); } p.getOutputStream().close(); GobblerThread gobbler = new GobblerThread(p, command, dir); gobbler.start(); String r = null; try (BufferedReader lineRead = new BufferedReader( new InputStreamReader(p.getInputStream(), encoding))) { r = lineRead.readLine(); if (debug) { LOG.debug("readpipe may return '" + r + "'"); LOG.debug("remaining output:\n"); String l; while ((l = lineRead.readLine()) != null) { LOG.debug(l); } } } for (;;) { try { int rc = p.waitFor(); gobbler.join(); if (rc == 0 && !gobbler.fail.get()) { return r; } else { if (debug) { LOG.debug("readpipe rc=" + rc); } throw new CommandFailedException(rc, gobbler.errorMessage.get(), gobbler.exception.get()); } } catch (InterruptedException ie) { } } } catch (IOException e) { LOG.error("Caught exception in FS.readPipe()", e); } catch (AccessControlException e) { LOG.warn( "FS.readPipe() isn't allowed for command '{}'. Working directory: '{}'. Required permission: {}", command, dir, e.getPermission()); } catch (SecurityException e) { LOG.warn( "FS.readPipe() isn't allowed for command '{}'. Working directory: '{}'", command, dir); } if (debug) { LOG.debug("readpipe returns null"); } return null; }

Target:
protected static String readPipe(File dir, String[] command, String encoding, Map<String, String> env) throws CommandFailedException { final boolean debug = LOG.isDebugEnabled(); try { if (debug) { LOG.debug("readpipe " + Arrays.asList(command) + "," + dir); } ProcessBuilder pb = new ProcessBuilder(command); pb.directory(dir); if (env != null) { pb.environment().putAll(env); } Process p; try { p = pb.start(); } catch (IOException e) { throw new CommandFailedException(-1, e.getMessage(), e); } p.getOutputStream().close(); GobblerThread gobbler = new GobblerThread(p, command, dir); gobbler.start(); String r = null; try (BufferedReader lineRead = new BufferedReader( new InputStreamReader(p.getInputStream(), encoding))) { r = lineRead.readLine(); if (debug) { LOG.debug("readpipe may return '" + r + "'"); LOG.debug("remaining output:\n"); String l; while ((l = lineRead.readLine()) != null) { LOG.debug(l); } } } for (;;) { try { int rc = p.waitFor(); gobbler.join(); if (rc == 0 && !gobbler.fail.get()) { return r; } else { if (debug) { LOG.debug("readpipe rc=" + rc); } throw new CommandFailedException(rc, gobbler.errorMessage.get(), gobbler.exception.get()); } } catch (InterruptedException ie) { } } } catch (IOException e) { LOG.error("Caught exception in FS.readPipe()", e); } catch (AccessControlException e) { LOG.warn(MessageFormat.format( JGitText.get().readPipeIsNotAllowedRequiredPermission, command, dir, e.getPermission())); } catch (SecurityException e) { LOG.warn(MessageFormat.format(JGitText.get().readPipeIsNotAllowed, command, dir)); } if (debug) { LOG.debug("readpipe returns null"); } return null; }