Skip to content

Prevent NPE with rootLogger shorthand when no appenders are specified - #3650

Merged
ppkarwasz merged 2 commits into
apache:2.xfrom
jhl221123:fix/2.x/3206-npe-shorthand
May 8, 2025
Merged

ppkarwasz merged 2 commits into
apache:2.xfrom
jhl221123:fix/2.x/3206-npe-shorthand

Conversation

@jhl221123

Copy link
Copy Markdown
Contributor

This pull request addresses issue #3206, which could lead to a NullPointerException when using the shorthand notation for the root logger (e.g., rootLogger = INFO) in log4j2.properties without explicitly defining any appender references.

To resolve this, the static helper method LoggerConfig.getLevelAndRefs() has been updated to ensure that the LevelAndRefs container always holds a non-null list of AppenderRef objects. When no appenders are specified in the shorthand string, the method has been updated to return an empty list instead of null.

Checklist

  • Base your changes on 2.x branch if you are targeting Log4j 2; use main otherwise
  • ./mvnw verify succeeds (if it fails due to code formatting issues reported by Spotless, simply run ./mvnw spotless:apply and retry)
  • Non-trivial changes contain an entry file in the src/changelog/.2.x.x directory
  • Tests for the changes are provided
  • Commits are signed (optional, but highly recommended)

@ppkarwasz ppkarwasz moved this from To triage to In review in Log4j bug tracker May 6, 2025
@github-actions

github-actions Bot commented May 6, 2025 •

Copy link
Copy Markdown
Contributor
Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 ✅ Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 ✅ Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 ✅ Build Scan PUBLISHED
Generated by gradle/develocity-actions

@ppkarwasz ppkarwasz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Can you add a changelog entry to the src/changelog/.2.x.x folder. The type of the entry should be fixed.

@jhl221123

Copy link
Copy Markdown
Contributor Author

Thanks, @ppkarwasz! I've added the changelog entry. I appreciate your guidance and review!

@ppkarwasz

Copy link
Copy Markdown
Member

I've added the changelog entry. I appreciate your guidance and review!

Thanks!

For some reason I don't fully understand the required GitHub Action workflows didn't start on your last commit.

  • @vy any idea why?
  • @jhl221123, could you try updating the branch again, e.g. git rebase -f origin/2.x; git push -f? Maybe it is a temporary problem and it will work for the next commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants