logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (LOG4J2-1538) Dynamic removal of filter may cause NPE
Date Tue, 23 Aug 2016 00:26:20 GMT

     [ https://issues.apache.org/jira/browse/LOG4J2-1538?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Gary Gregory resolved LOG4J2-1538.
----------------------------------
       Resolution: Fixed
    Fix Version/s: 2.7

Igor,

Thank you for your report and fix. 

This was the only place where getFilter() was called more than once from in one method.

Keep' em coming!

Gary

> Dynamic removal of filter may cause NPE
> ---------------------------------------
>
>                 Key: LOG4J2-1538
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1538
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.6.2
>            Reporter: Igor Karpov
>             Fix For: 2.7
>
>   Original Estimate: 1m
>  Remaining Estimate: 1m
>
> In my application, I need to add and remove a filter dynamically.
> The problem is, that it occasionally causes NPE because of the subtle bug in 
> AppenderControl.isFilteredByAppenderControl:
> {code:java}
> @PerformanceSensitive
>     private boolean isFilteredByAppenderControl(LogEvent event) {
>         return this.getFilter() != null && Result.DENY == this.getFilter().filter(event);
>     }
> {code}
> here, this.getFilter() is called twice.
> getFilter() is defined in superclass, AbstractFilterable:
> private volatile Filter filter;
> so, it's volatile, and in my case, when I dynamically remove the filter it becomes null,
and in certain cases it happens right between the two calls to getFilter().
> The first call to getFilter() returns non-null, so the secand call is performed, which
returns null and it causes NPE.
> The easy fix for this is not to call getFilter() twice:
> {code:java}
> @PerformanceSensitive
>     private boolean isFilteredByAppenderControl(LogEvent event) {
>         Filter filter = this.getFilter(); // do not inline, filter is volatile
>         return filter != null && Result.DENY == filter.filter(event);
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message