You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "JWT007 (via GitHub)" <gi...@apache.org> on 2025/02/12 23:34:40 UTC

[I] DefaultFilterComponentBuilder creates builder attributes for onMatch/onMismatch without performing null checks. (logging-log4j2)

JWT007 opened a new issue, #3464:
URL: https://github.com/apache/logging-log4j2/issues/3464

   Log4j 2.24.3
   ---
   When using a configuration builder and adding a FilterComponentBuilder, generating XML from the ConfigurationBuilder causes exception when the filter is defined with a null OnMatch/OnMismatch Result.
   
   Configuring the onMatch/onMismatch attributes is not required - null should be a valid value.
   
   In this case, no attributtes should be added.
   
   However in tthe DefaulttFilterComponentBuilder, attributes are added to tthe builder without performing a null-check first.
   
   ```
   class DefaultFilterComponentBuilder extends DefaultComponentAndConfigurationBuilder<FilterComponentBuilder>
           implements FilterComponentBuilder {
   
       public DefaultFilterComponentBuilder(
               final DefaultConfigurationBuilder<? extends Configuration> builder,
               final String type,
               final String onMatch,
               final String onMismatch) {
           super(builder, type);
           addAttribute(AbstractFilterBuilder.ATTR_ON_MATCH, onMatch);
           addAttribute(AbstractFilterBuilder.ATTR_ON_MISMATCH, onMismatch);
       }
   }
   ```
   
   This results attributes with *null* values in the builder tree which can cause XML serialization problems.
   
   I think this might be better:
   
   ```
   class DefaultFilterComponentBuilder extends DefaultComponentAndConfigurationBuilder<FilterComponentBuilder>
           implements FilterComponentBuilder {
   
       public DefaultFilterComponentBuilder(
               final DefaultConfigurationBuilder<? extends Configuration> builder,
               final String type,
               final String onMatch,
               final String onMismatch) {
           super(builder, type);
           Optional.ofNullable(onMatch).ifPresent(() -> addAttribute(AbstractFilterBuilder.ATTR_ON_MATCH, onMatch));
           Optional.ofNullable(onMismatch).ifPresent(() -> addAttribute(AbstractFilterBuilder.ATTR_ON_MISMATCH, onMismatch));
       }
   }
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] DefaultFilterComponentBuilder creates builder attributes for onMatch/onMismatch without performing null checks. [logging-log4j2]

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz closed issue #3464: DefaultFilterComponentBuilder creates builder attributes for onMatch/onMismatch without performing null checks.
URL: https://github.com/apache/logging-log4j2/issues/3464


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] DefaultFilterComponentBuilder creates builder attributes for onMatch/onMismatch without performing null checks. [logging-log4j2]

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #3464:
URL: https://github.com/apache/logging-log4j2/issues/3464#issuecomment-2671316280

   I am closing this as duplicate of #2791.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org