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

AsyncWaitStrategyFactoryConfig - potential NPE when creating programatically #3159

Open
JWT007 opened this issue Nov 4, 2024 · 3 comments
Open

Comments

@JWT007
Copy link
Contributor

JWT007 commented Nov 4, 2024

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)
@JWT007
Copy link
Contributor Author

JWT007 commented Nov 9, 2024

@ppkarwasz I am not sure why the bot didn't mark this as "waiting for maintainer" - not sure if it pops up for you?

@ppkarwasz
Copy link
Contributor

I am seriously considering deprecating AsyncWaitStrategyFactoryConfig. I will discuss it with the other maintainers (especially @remkop, who introduced it), but it could probably be replaced with the log4j2.asyncLoggerConfigWaitStrategy Log4j configuration property.

The presence of both a Log4j configuration property and a direct child of <Configuration> IMHO needlessly complexifies the logic to determine which waiting strategy to use. In main we have a simple DI system and the WaitStrategy beans are the only ones that need a Configuration parameter.

@ppkarwasz
Copy link
Contributor

I am not sure why the bot didn't mark this as "waiting for maintainer" - not sure if it pops up for you?

You are a CONTRIBUTOR now! 😉
The labels are pretty much a work in progress and "waiting for maintainer" is mostly there to make a triage and ask the user some basic questions. Your issues usually don't need more information, so you can consider them accepted by default.

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

2 participants