logging-log4j2 icon indicating copy to clipboard operation
logging-log4j2 copied to clipboard

RegexReplacement static factory method doesn't handle null 'replacement' attribute correctly

Open JWT007 opened this issue 1 year ago • 2 comments

RegexReplacement#createRegexReplacement

Static builder method returns nullif the regexattribute is null, but although it logs an error it does not return null if the replacement attribute is null.

public static RegexReplacement createRegexReplacement(
        @PluginAttribute("regex") final Pattern regex, @PluginAttribute("replacement") final String replacement) {
    if (regex == null) {
        LOGGER.error("A regular expression is required for replacement");
        return null;
    }
    if (replacement == null) {
        LOGGER.error("A replacement string is required to perform replacement");
    }
    // FIXME: should we use Matcher.quoteReplacement() here?
    return new RegexReplacement(regex, replacement);
}

JWT007 avatar Nov 18 '24 17:11 JWT007

I can work on this @ppkarwasz feel free too assign this to me :)

jaykataria1111 avatar Jan 16 '25 06:01 jaykataria1111

@ppkarwasz - another small PR - simple fix

@jaykataria1111 - sorry to steal this one from you :( - its been a month and I am trying to close out some of the tickets I created before the next release.

JWT007 avatar Feb 11 '25 23:02 JWT007