Skip to content

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

Open
@JWT007

Description

@JWT007
Contributor

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);
}

Activity

jaykataria1111

jaykataria1111 commented on Jan 16, 2025

@jaykataria1111
Contributor

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

JWT007

JWT007 commented on Feb 11, 2025

@JWT007
ContributorAuthor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

To triage

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @JWT007@jaykataria1111

      Issue actions

        RegexReplacement static factory method doesn't handle null 'replacement' attribute correctly · Issue #3215 · apache/logging-log4j2