aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSmokowski, Kevin (ks6305) <ks6305@att.com>2018-08-02 14:37:21 +0000
committerSmokowski, Kevin (ks6305) <ks6305@att.com>2018-08-02 14:37:21 +0000
commit1ff267b4fc1d964d6a0f283f22b07237bb6a1163 (patch)
tree531b072a52bfca5707c69a51fecfc2f0d8391bf0
parentc99b602cf71da724073bedb6a30f2e0659a9dbde (diff)
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) <ks6305@att.com>
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MetricLogger.java8
-rw-r--r--sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java11
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 9d263456..b4bd2017 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 31a419bb..971a700f 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);
+ }
}