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

NPE when using rootLogger shorthand properties notation #3206

Open
ayush11-96 opened this issue Nov 14, 2024 · 8 comments
Open

NPE when using rootLogger shorthand properties notation #3206

ayush11-96 opened this issue Nov 14, 2024 · 8 comments
Labels
bug Incorrect, unexpected, or unintended behavior of existing code good first issue Issues that are good for contributors looking to get started

Comments

@ayush11-96
Copy link

ayush11-96 commented Nov 14, 2024

Currently we are using log4j2 version 2.17.0 with spring boot but while updating log4j2 to 2.17.2 we are getting below error and which is because of the appender of root is initialise to null
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because the return value of "org.apache.logging.log4j.core.config.LoggerConfig.getAppenderRefs()" is null

We are passing below properties:

rootLogger.appenderRef.console.ref=console
rootLogger.appenderRefs=console
rootLogger=INFO

Please help us to understand if we require some changes along with version upgrade?

@ppkarwasz
Copy link
Contributor

@ayush11-96,

Does the problem also occur with version 2.24.1?
Can you provide the full stack trace of the exception?

@ppkarwasz ppkarwasz added waiting-for-user More information is needed from the user and removed waiting-for-maintainer labels Nov 14, 2024
@ayush11-96
Copy link
Author

ayush11-96 commented Nov 14, 2024

@ppkarwasz
I tried till 2.23.1 version and this is still happening
Stack Trace:

Caused by: java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because the return value of "org.apache.logging.log4j.core.config.LoggerConfig.getAppenderRefs()" is null
	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:740) ~[log4j-core-2.23.1.jar:2.23.1]
	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:264) ~[log4j-core-2.23.1.jar:2.23.1]
	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:313) ~[log4j-core-2.23.1.jar:2.23.1]
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:631) ~[log4j-core-2.23.1.jar:2.23.1]
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:292) ~[log4j-core-2.23.1.jar:2.23.1]

@github-actions github-actions bot added waiting-for-maintainer and removed waiting-for-user More information is needed from the user labels Nov 14, 2024
@ppkarwasz ppkarwasz changed the title LoggerConfig.getAppenderRefs() is null for Root logger appender NPE when using rootLogger shorthand properties notation Nov 14, 2024
@ppkarwasz ppkarwasz added the bug Incorrect, unexpected, or unintended behavior of existing code label Nov 14, 2024
@ayush11-96
Copy link
Author

@ppkarwasz could u please elaborate the issue if u got that?

@ppkarwasz
Copy link
Contributor

@ayush11-96,

There is problem in your configuration: you both use the shorthand rootLogger = <level>, <ref1>, <ref2> notation that was introduced in Log4j Core 2.17.2 IIRC (see Properties configuration quirks for more information) and the normal rootLogger.appenderRef.<n>.ref properties.
You should either use the long notation:

rootLogger.level = INFO
rootLogger.appenderRef.0.ref = console

or the shorthand notation (which only exists in the Java properties format):

rootLogger = INFO, console

The NPE is due to the fact that the current code does not handle the case, when the shorthand notation is used and no appender reference is provided (rootLogger = INFO). We will fix this in the next release.

@ayush11-96
Copy link
Author

Thanks @ppkarwasz
Can I expect any ETA for the new version with fix?

@ppkarwasz ppkarwasz added the good first issue Issues that are good for contributors looking to get started label Nov 14, 2024
@ppkarwasz
Copy link
Contributor

Thanks @ppkarwasz Can I expect any ETA for the new version with fix?

This bug only affects very unlikely configuration scenario, when a user does not want any appenders for the root logger. It is not a priority.

Your configuration triggered the bug, because you have a typo in your configuration: replace rootLogger = INFO with rootLogger.level = INFO and everything will work. See my comment above for two variants of a working configuration.

@ayush11-96
Copy link
Author

thanks @ppkarwasz

@ppkarwasz ppkarwasz reopened this Nov 14, 2024
@ppkarwasz
Copy link
Contributor

I keep this open, so we can fix the NPE in the rare case a user really does not want any appenders attached to the root logger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect, unexpected, or unintended behavior of existing code good first issue Issues that are good for contributors looking to get started
Projects
None yet
Development

No branches or pull requests

2 participants