aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dt5972@att.com>2018-08-02 20:59:50 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-02 20:59:50 +0000
commit7ca3ec58f2d2f05322803b1e4b39e730248d1a1b (patch)
tree162c33282e3d3633ce91e39373cb2b9cde88e269
parentde9fb16753eefa333dc3e44330062621b17b2ac2 (diff)
parent1ff267b4fc1d964d6a0f283f22b07237bb6a1163 (diff)
Merge "add null check to format string"
-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);
+ }
}