Repository navigation
test(spring-boot): Keep the Log4j2 LoggerContext reachable in appender auto-configuration tests - #6488
Merged
Conversation
…r auto-configuration tests
📲 Install BuildsAndroid
|
markushi
marked this pull request as ready for review
November 6, 2026 09:01
markushi
requested review from
romtsn and
runningcode
and removed request for
a team
November 6, 2026 09:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
SentryLog4j2AppenderAutoConfigurationTest(insentry-spring-boot-jakartaandsentry-spring-boot-4) now keeps a strong reference to the Log4j2LoggerContextfor the whole test. Before, it read the context again withLogManager.getContext(false)on every access.Test-only change.
💡 Motivation and Context
ClassLoaderContextSelectorholds eachLoggerContextonly through aWeakReference. The test kept no strong reference. If a GC ran during the Spring context startup, Log4j2 collected the context and made a new one with a freshDefaultConfiguration. Appenders that the test added before were then gone.This made
does not configure SentryAppender when appender is already configuredfail: the root logger then had onlySENTRY_APPENDER, notcustomAppender. The result depends on GC timing. It fails every time on my machine onmain, and it failed twice in a row on theBuild Job ubuntu-latestCI job of #6231, which does not touch Spring or Log4j2.💚 How did you test it?
mainevery time on my machine, also when run alone.LoggerContextidentity inside the Spring context was different from the one before it. When the test held a strong reference, the identity stayed the same and the test passed../gradlew :sentry-spring-boot-jakarta:test :sentry-spring-boot-4:testpasses.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Rerun CI on #6231 after this merges.
🤖 Generated with Claude Code
#skip-changelog