Oliver Limberg created LOG4J2-2931:
--------------------------------------

             Summary: Configuring CompositeFilter via properties will generate 
error due to invalid arguments
                 Key: LOG4J2-2931
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2931
             Project: Log4j 2
          Issue Type: Improvement
          Components: Core
    Affects Versions: 2.13.3
            Reporter: Oliver Limberg
         Attachments: CompositeFilterPropertiesTest.java, 
log4j2-composite-filter.properties

The attached filter will produce the following errors:

 
{noformat}
ERROR filters contains invalid attributes "onMatch", "onMismatch"
ERROR filters contains invalid attributes "onMatch", "onMismatch"
{noformat}
When the configuration is built, using DefaultConfigurationBuilder, filters are 
always built using the class DefaultFilterComponentBuilder.
The constructor will always add the two attributes 'onMatch' and 'onMismatch'.
However, the createFilters method (annotated with PluginFactory) of 
CompositeFilter, does not specify the two attributes, so they remain in the 
list of node attributes in PluginBuilder and when calling 
checkForRemainingAttributes, the error statements are generated.



A simple solution could be to change the signature of createFilters to include 
those two attributes. The constructor of the CompositeFilter could stay 
untouched.
{code:java}
@PluginFactory
public static CompositeFilter createFilters(@PluginElement("Filters") final 
Filter[] filters,
                                            @PluginAttribute("onMatch") final 
Result match,
                                            @PluginAttribute("onMismatch") 
final Result mismatch) {
    return new CompositeFilter(filters);
}{code}
This solution would required to make a minor change in addFilter of class 
AbstractFilterable and its test class.
Another solution would be to modify the DefaultFilterComponentBuilder or even 
use DefaultCompositeFilterComponentBuilder when applicable in 
DefaultConfigurationBuilder.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to