Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LOGMGR-191] Amend NullPointerException in RegexFilter.isLoggable() #172

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/jboss/logmanager/filters/RegexFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ public RegexFilter(final String patternString) {
@Override
public boolean isLoggable(final LogRecord record) {
if (record instanceof ExtLogRecord) {
if (((ExtLogRecord) record).getFormattedMessage() == null) {
return false;
}
return pattern.matcher(((ExtLogRecord) record).getFormattedMessage()).find();
}
if (record.getMessage() == null) {
return false;
}
return pattern.matcher(record.getMessage()).find();
}
}
17 changes: 17 additions & 0 deletions src/test/java/org/jboss/logmanager/FilterTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,23 @@ public void testRegexFilter3() {
assertFalse("Handler was run", ran.get());
}

@Test
public void testRegexFilter4() {
final Filter filter = new RegexFilter("pest");
final AtomicBoolean ran = new AtomicBoolean();
final Handler handler = new CheckingHandler(ran);
final Logger logger = Logger.getLogger("filterTest");
final ExtLogRecord record = new ExtLogRecord(Level.ERROR, null, FormatStyle.MESSAGE_FORMAT, "filterTest");
record.setThrown(new Exception());
logger.setUseParentHandlers(false);
logger.addHandler(handler);
logger.setLevel(Level.INFO);
logger.setFilter(filter);
handler.setLevel(Level.INFO);
logger.log(record);
assertFalse("Handler was run", ran.get());
}

@Test
public void testSubstitueFilter0() {
final Filter filter = new SubstituteFilter(Pattern.compile("test"), "lunch", true);
Expand Down