Skip to content

Conversation

jhl221123
Copy link
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
Copy link

github-actions bot commented May 6, 2025

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

Copy link
Contributor

@ppkarwasz ppkarwasz left a comment

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
Contributor Author

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

@ppkarwasz
Copy link
Contributor

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.

@jhl221123 jhl221123 force-pushed the fix/2.x/3206-npe-shorthand branch from d075a70 to 2a7ce22 Compare May 8, 2025 13:50
@ppkarwasz ppkarwasz merged commit 4a7ddf1 into apache:2.x May 8, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in Log4j bug tracker May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants