Merge branch 'stable-2.14' into stable-2.15 * stable-2.14: [HookTask] Avoid shadowing field [HookTask] Close readers in try-with-resources Change-Id: I4cc4b9dc7aafe058839ba373b741f9daa3a94160
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java index 7fbf1a7..b6654da 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java +++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java
@@ -107,9 +107,9 @@ ps = pb.start(); ps.getOutputStream().close(); - String output = new String(ByteStreams.toByteArray(ps.getInputStream()), UTF_8); + String out = new String(ByteStreams.toByteArray(ps.getInputStream()), UTF_8); ps.waitFor(); - result = new HookResult(ps.exitValue(), output); + result = new HookResult(ps.exitValue(), out); } catch (InterruptedException iex) { // InterruptedException - timeout or cancel args.metrics.timeout(name); @@ -126,12 +126,10 @@ } if (log.isDebugEnabled()) { - BufferedReader br = new BufferedReader(new StringReader(result.getOutput())); - try { - String line; - while ((line = br.readLine()) != null) { - log.debug("hook[{}] output: {}", name, line); - } + try (BufferedReader br = new BufferedReader(new StringReader(result.getOutput()))) { + br.lines() + .filter(s -> !s.isEmpty()) + .forEach(line -> log.debug("hook[{}] output: {}", name, line)); } catch (IOException iox) { log.error("Error writing hook [{}] output", name, iox); }