Skip to content

Application-managed JUL bridge handler should only be removed if installed - #50779

Merged
snicoll merged 2 commits into
spring-projects:4.0.xfrom
dhruv-15-03:fix-jul-bridge-uninstall-asymmetry
Jul 14, 2026
Merged

Application-managed JUL bridge handler should only be removed if installed#50779
snicoll merged 2 commits into
spring-projects:4.0.xfrom
dhruv-15-03:fix-jul-bridge-uninstall-asymmetry

Conversation

@dhruv-15-03

Copy link
Copy Markdown
Contributor

This addresses the install/uninstall asymmetry described in #33697.

LogbackLoggingSystem and Log4J2LoggingSystem install a JUL bridge handler (SLF4JBridgeHandler / Log4jBridgeHandler) only when the application is not already managing java.util.logging itself (i.e. when the JUL root logger is using at most a single ConsoleHandler). However, cleanUp() removed the bridge handler whenever the bridge class was merely present on the classpath.

As a result, when an application installs and manages its own JUL bridge handler, Spring Boot would still uninstall it during context shutdown — tearing down a handler it never installed.

This change tracks whether the bridge handler was installed by Spring Boot and only removes it during cleanup when that is the case, making install and uninstall symmetric.

A test is added to each logging system verifying that an application-installed bridge handler is left in place after cleanUp(). Both tests fail without the corresponding production change.

Note: this PR is scoped to the install/uninstall asymmetry. The separate question of when the bridge handler is removed during the context lifecycle (also discussed in the issue) is intentionally left out of scope.

Copilot AI review requested due to automatic review settings June 16, 2026 17:20

This comment was marked as low quality.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 16, 2026
@dhruv-15-03
dhruv-15-03 force-pushed the fix-jul-bridge-uninstall-asymmetry branch from cbbdf78 to 8d5b363 Compare June 24, 2026 15:54
@dhruv-15-03

Copy link
Copy Markdown
Contributor Author

Hi team! Just wanted to gently follow up on this PR. I've rebased it on the latest main to keep it current. Happy to make any changes or provide more context if it would help with the review. Thanks for your time!

Comment on lines +346 to +347
// gh-33697: the application manages its own JUL-to-SLF4J bridge, so Spring Boot
// must not uninstall a bridge handler that it did not install itself.

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.

Please remove this comment. The test method is well named so the comment doesn't really add anything.

Comment on lines +428 to +429
// gh-33697: the application manages its own JUL-to-Log4j bridge, so Spring Boot
// must not uninstall a bridge handler that it did not install itself.

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.

Please remove this comment. The test method is well named so the comment doesn't really add anything.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Jun 28, 2026
@dhruv-15-03

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @wilkinsona! I've removed the two redundant gh-33697 comments as requested in db97069 -- the branch is up to date and DCO is passing. Whenever you get a chance, I'd appreciate a re-review.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 10, 2026
@snicoll snicoll changed the title Avoid removing application-managed JUL bridge handler Slf4JBridgeHandler.uninstall called too early in context close, swallowing JUL log output Jul 14, 2026
@snicoll snicoll changed the title Slf4JBridgeHandler.uninstall called too early in context close, swallowing JUL log output Application-managed JUL bridge handler should only be removed if installed Jul 14, 2026
@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Jul 14, 2026
@snicoll snicoll self-assigned this Jul 14, 2026
@snicoll snicoll added this to the 4.0.8 milestone Jul 14, 2026
dhruv-15-03 and others added 2 commits July 14, 2026 18:11
`LogbackLoggingSystem` and `Log4J2LoggingSystem` install a JUL bridge
handler only when the application is not already managing `java.util.logging`.
However, `cleanUp()` removed the bridge handler whenever the bridge class
was present on the classpath, so Spring Boot uninstalled a bridge handler
that an application had installed and managed itself.

Track whether the bridge handler was installed by Spring Boot and only
remove it during cleanup when that is the case.

See spring-projectsgh-50779

Signed-off-by: dhruv-15-03 <dhruvrastogi2004@gmail.com>
@snicoll
snicoll force-pushed the fix-jul-bridge-uninstall-asymmetry branch from db97069 to a2af5ac Compare July 14, 2026 16:19
@snicoll
snicoll changed the base branch from main to 4.0.x July 14, 2026 16:19
@snicoll
snicoll merged commit b75932f into spring-projects:4.0.x Jul 14, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants