Skip to content

NPE when using rootLogger shorthand properties notation #3206

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

Closed
ayush11-96 opened this issue Nov 14, 2024 · 12 comments
Closed

NPE when using rootLogger shorthand properties notation #3206

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

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.

@jhl221123
Copy link
Contributor

Hi @ppkarwasz,

I'd like to work on this good first issue regarding the NPE.

Since it's in 'To triage', please let me know if it's available for contribution.

Thanks!

@ppkarwasz ppkarwasz moved this from To triage to In progress in Log4j bug tracker May 6, 2025
@ppkarwasz
Copy link
Contributor

@jhl221123,

Go ahead, thanks!

Since it's in 'To triage', please let me know if it's available for contribution.

I introduced the Log4j bug tracker, so many of the old reports are in the To triage state even if they were triaged before.

jhl221123 added a commit to jhl221123/logging-log4j2 that referenced this issue May 8, 2025
ppkarwasz pushed a commit that referenced this issue May 8, 2025
…#3650)

* Fix NPE with rootLogger shorthand when no appenders are specified

* Add changelog entry for #3206
@injae-kim
Copy link

fix PR: #3650

can we close this issue cause fix PR is merged? 😄

@ppkarwasz
Copy link
Contributor

@injae-kim,

Thanks, usually GitHub closes related issues automatically but apparently none of the magic close/fix/resolve words were used to link the PR to the issue.

@github-project-automation github-project-automation bot moved this from In progress to Done in Log4j bug tracker May 9, 2025
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 waiting-for-maintainer
Projects
Status: Done
Development

No branches or pull requests

4 participants