summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);
+ }
}