From 0e44012994b452a3e65cfaef1f1152c1fb04bd7f Mon Sep 17 00:00:00 2001 From: Ray Milkey Date: Tue, 16 Jan 2018 15:00:50 -0800 Subject: [PATCH] Fix stack trace when encountering a checkstyle error Change-Id: If1b7edd9aaf1779251b339dbef254fcc1b0e4690 --- .../org/onosproject/buckdaemon/BuckDaemon.java | 6 +++++- .../onosproject/buckdaemon/BuckTaskContext.java | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/build/conf/src/main/java/org/onosproject/buckdaemon/BuckDaemon.java b/tools/build/conf/src/main/java/org/onosproject/buckdaemon/BuckDaemon.java index 56deadd201..f3166b1214 100644 --- a/tools/build/conf/src/main/java/org/onosproject/buckdaemon/BuckDaemon.java +++ b/tools/build/conf/src/main/java/org/onosproject/buckdaemon/BuckDaemon.java @@ -175,7 +175,11 @@ public final class BuckDaemon { try { try { socket.setSoTimeout(1_000); //reads should time out after 1 second - BuckTaskContext context = new BuckTaskContext(socket.getInputStream()); + BuckTaskContext context = BuckTaskContext.createBuckTaskContext(socket.getInputStream()); + if (context == null) { + socket.close(); + return; + } String taskName = context.taskName(); BuckTask task = tasks.get(taskName); diff --git a/tools/build/conf/src/main/java/org/onosproject/buckdaemon/BuckTaskContext.java b/tools/build/conf/src/main/java/org/onosproject/buckdaemon/BuckTaskContext.java index b8d189c4d4..2cfb35dcb3 100644 --- a/tools/build/conf/src/main/java/org/onosproject/buckdaemon/BuckTaskContext.java +++ b/tools/build/conf/src/main/java/org/onosproject/buckdaemon/BuckTaskContext.java @@ -36,10 +36,16 @@ public class BuckTaskContext { private final ImmutableList input; private final List output; - BuckTaskContext(InputStream inputStream) throws IOException { + public static BuckTaskContext createBuckTaskContext(InputStream inputStream) throws IOException { ImmutableList lines = slurpInput(inputStream); - checkArgument(lines.size() >= 1 && !lines.get(0).isEmpty(), - "Request must contain at least task type"); + if (lines.size() == 0) { + return null; + } else { + return new BuckTaskContext(lines); + } + } + + BuckTaskContext(ImmutableList lines) { this.taskName = lines.get(0); this.input = lines.subList(1, lines.size()); this.output = Lists.newArrayList(); @@ -55,7 +61,7 @@ public class BuckTaskContext { private static ImmutableList slurpInput(InputStream stream) throws IOException { ImmutableList.Builder lines = ImmutableList.builder(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream)); - while(true) { + while (true) { String line = bufferedReader.readLine(); if (line == null || line.trim().length() == 0) { // Empty line or EOF