Skip to content

AsyncWaitStrategyFactoryConfig - potential NPE when creating programatically #3159

@JWT007

Description

@JWT007

AsyncWaitStrategyFactoryConfig (Log4j 2.24.1)

This @Plugin doesn't behave like most others where if the configuration is invalid, it will return a null from the Builder.

The @PluginBuilderAttribute factoryClassName (for the XML class attribute) is marked as @Required, but if creating programatically the missing value is not checked and the constructor will throw a NPE.

@Override
public AsyncWaitStrategyFactoryConfig build() {
    return new AsyncWaitStrategyFactoryConfig(factoryClassName);
}
public AsyncWaitStrategyFactoryConfig(final String factoryClassName) {
    this.factoryClassName = Objects.requireNonNull(factoryClassName, "factoryClassName");
}

Typical behaviour here would be to return null from the build() method if misconfigured.

  • adding a NotEmpty check to the Builder#withFactoryClassName(...) method might be sensible.
  • adding a NotEmpty check to the constructor might be sensible (an empty string here makes no sense)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions