Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegexFilter auto-boxing of Boolean useRawMsg can lead to NPE #3239

Open
JWT007 opened this issue Nov 26, 2024 · 1 comment
Open

RegexFilter auto-boxing of Boolean useRawMsg can lead to NPE #3239

JWT007 opened this issue Nov 26, 2024 · 1 comment
Assignees

Comments

@JWT007
Copy link
Contributor

JWT007 commented Nov 26, 2024

In RegexFilter.Builder (2.24.1) the PluginAttribute for useRawMsg is a Boolean default null.

@PluginFactory
public static RegexFilter createFilter(
        // @formatter:off
        @PluginAttribute("regex") final String regex,
        @PluginElement("PatternFlags") final String[] patternFlags,
        @PluginAttribute("useRawMsg") final Boolean useRawMsg,
        @PluginAttribute("onMatch") final Result match,
        @PluginAttribute("onMismatch") final Result mismatch)
        // @formatter:on
        throws IllegalArgumentException, IllegalAccessException {
    if (regex == null) {
        LOGGER.error("A regular expression must be provided for RegexFilter");
        return null;
    }
    return new RegexFilter(useRawMsg, Pattern.compile(regex, toPatternFlags(patternFlags)), match, mismatch);
}

The RegexFilter constructor expects a boolean primitive.

private RegexFilter(final boolean raw, final Pattern pattern, final Result onMatch, final Result onMismatch) {
    super(onMatch, onMismatch);
    this.pattern = pattern;
    this.useRawMessage = raw;
}

I believe, if the useRawMsg attribute is not set (undefined/null), auto-boxing from Boolean to boolean will cause/throw a NPE which is not caught and the builder will not return null as it should?

Also, the 'regex' attribute should probably be defined as @required for the isValid() builder-functionality to work correctly.

@jaykataria1111
Copy link
Contributor

@ppkarwasz , please assign this to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants