From 5df6412cd6bd05b4fc9392d4fd6e7ac6369604bb Mon Sep 17 00:00:00 2001 From: Magesh Umasankar Date: Fri, 15 Mar 2002 01:15:25 +0000 Subject: [PATCH] Check for possible null message and/or null stream. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271846 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/listener/AnsiColorLogger.java | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/main/org/apache/tools/ant/listener/AnsiColorLogger.java b/src/main/org/apache/tools/ant/listener/AnsiColorLogger.java index 96e0688f1..e3651bc9f 100644 --- a/src/main/org/apache/tools/ant/listener/AnsiColorLogger.java +++ b/src/main/org/apache/tools/ant/listener/AnsiColorLogger.java @@ -231,35 +231,37 @@ public final class AnsiColorLogger extends DefaultLogger { protected final void printMessage(final String message, final PrintStream stream, final int priority) { - if (!colorsSet) { - setColors(); - colorsSet = true; - } + if (message != null && stream != null) { + if (!colorsSet) { + setColors(); + colorsSet = true; + } - final StringBuffer msg = new StringBuffer(message); - switch (priority) { - case Project.MSG_ERR: - msg.insert(0, errColor); - msg.append(END_COLOR); - break; - case Project.MSG_WARN: - msg.insert(0, warnColor); - msg.append(END_COLOR); - break; - case Project.MSG_INFO: - msg.insert(0, infoColor); - msg.append(END_COLOR); - break; - case Project.MSG_VERBOSE: - msg.insert(0, verboseColor); - msg.append(END_COLOR); - break; - case Project.MSG_DEBUG: - msg.insert(0, debugColor); - msg.append(END_COLOR); - break; + final StringBuffer msg = new StringBuffer(message); + switch (priority) { + case Project.MSG_ERR: + msg.insert(0, errColor); + msg.append(END_COLOR); + break; + case Project.MSG_WARN: + msg.insert(0, warnColor); + msg.append(END_COLOR); + break; + case Project.MSG_INFO: + msg.insert(0, infoColor); + msg.append(END_COLOR); + break; + case Project.MSG_VERBOSE: + msg.insert(0, verboseColor); + msg.append(END_COLOR); + break; + case Project.MSG_DEBUG: + msg.insert(0, debugColor); + msg.append(END_COLOR); + break; + } + final String strmessage = msg.toString(); + stream.println(strmessage); } - final String strmessage = msg.toString(); - stream.println(strmessage); } }