From 4badc67faceb4a11b204e6ad28119f76863b6c97 Mon Sep 17 00:00:00 2001 From: James Perkins Date: Thu, 8 Mar 2018 09:37:33 -0800 Subject: [PATCH] [LOGMGR-191] Handle null messages in regex filters. --- .../java/org/jboss/logmanager/filters/RegexFilter.java | 7 +++++-- .../org/jboss/logmanager/filters/SubstituteFilter.java | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jboss/logmanager/filters/RegexFilter.java b/src/main/java/org/jboss/logmanager/filters/RegexFilter.java index ee4e71a3..60b7d267 100644 --- a/src/main/java/org/jboss/logmanager/filters/RegexFilter.java +++ b/src/main/java/org/jboss/logmanager/filters/RegexFilter.java @@ -59,9 +59,12 @@ public RegexFilter(final String patternString) { */ @Override public boolean isLoggable(final LogRecord record) { + final String msg; if (record instanceof ExtLogRecord) { - return pattern.matcher(((ExtLogRecord) record).getFormattedMessage()).find(); + msg = ((ExtLogRecord) record).getFormattedMessage(); + } else { + msg = record.getMessage(); } - return pattern.matcher(record.getMessage()).find(); + return pattern.matcher(String.valueOf(msg)).find(); } } diff --git a/src/main/java/org/jboss/logmanager/filters/SubstituteFilter.java b/src/main/java/org/jboss/logmanager/filters/SubstituteFilter.java index efc083f4..98b5a617 100644 --- a/src/main/java/org/jboss/logmanager/filters/SubstituteFilter.java +++ b/src/main/java/org/jboss/logmanager/filters/SubstituteFilter.java @@ -73,12 +73,13 @@ public SubstituteFilter(final String patternString, final String replacement, fi */ @Override public boolean isLoggable(final LogRecord record) { - final Matcher matcher; + final String currentMsg; if (record instanceof ExtLogRecord) { - matcher = pattern.matcher(((ExtLogRecord) record).getFormattedMessage()); + currentMsg = ((ExtLogRecord) record).getFormattedMessage(); } else { - matcher = pattern.matcher(record.getMessage()); + currentMsg = record.getMessage(); } + final Matcher matcher = pattern.matcher(String.valueOf(currentMsg)); final String msg; if (replaceAll) { msg = matcher.replaceAll(replacement);