From 1ff267b4fc1d964d6a0f283f22b07237bb6a1163 Mon Sep 17 00:00:00 2001 From: "Smokowski, Kevin (ks6305)" Date: Thu, 2 Aug 2018 14:37:21 +0000 Subject: add null check to format string add null check to format string Change-Id: If82f751ec679189620e02fafdcd2e1af9258268f Issue-ID: CCSDK-424 Signed-off-by: Smokowski, Kevin (ks6305) --- .../main/java/org/onap/ccsdk/sli/core/sli/MetricLogger.java | 8 +++++--- .../java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java | 11 +++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MetricLogger.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MetricLogger.java index 9d263456c..b4bd2017e 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MetricLogger.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MetricLogger.java @@ -300,9 +300,11 @@ public class MetricLogger { } protected String formatString(String str) { - str = str.replaceAll("\\R",""); // this will strip all new line characters - str = str.replaceAll("\\|","%7C"); //log records should not contain a pipe, encode the pipe character - return str; + if (str != null) { + str = str.replaceAll("\\R", ""); // this will strip all new line characters + str = str.replaceAll("\\|", "%7C"); // log records should not contain a pipe, encode the pipe character + } + return str; } public static void resetContext() { diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java index 31a419bb1..971a700f5 100644 --- a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java @@ -129,7 +129,14 @@ public class TestMetricLogger { logger.asIso8601(System.currentTimeMillis()); } - - + @Test + public void formatString() { + String output = logger.formatString("\n"); + assertEquals("",output); + output = logger.formatString("|"); + assertEquals("%7C",output); + output = logger.formatString(null); + assertEquals(null,output); + } } -- cgit 1.2.3-korg