This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/release-2.x by this push:
     new 59204c4  LOG4J2-3121 config modified at run-time may trigger 
incomplete MBean re-initialization due to InstanceAlreadyExistsException (#547)
59204c4 is described below

commit 59204c45d0b4c6542ad9ff887a5d67c75b9fdc8a
Author: Markus Spann <[email protected]>
AuthorDate: Sun Jul 11 00:39:12 2021 +0200

    LOG4J2-3121 config modified at run-time may trigger incomplete MBean 
re-initialization due to InstanceAlreadyExistsException (#547)
    
    * LOG4J2-3121: log4j2 config modified at run-time may trigger incomplete 
MBean re-initialization due to InstanceAlreadyExistsException
    
    * LOG4J2-3121: Update for codestyle
    
    * LOG4J2-3121: Updated changes.xml with bugfix info
    
    Co-authored-by: Markus Spann <[email protected]>
    Co-authored-by: Volkan Yazıcı <[email protected]>
---
 .../src/main/java/org/apache/logging/log4j/core/jmx/Server.java   | 8 ++++++++
 src/changes/changes.xml                                           | 2 ++
 2 files changed, 10 insertions(+)

diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
index 04eaa3d..baf1f96 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
@@ -389,7 +389,15 @@ public final class Server {
 
     private static void register(final MBeanServer mbs, final Object mbean, 
final ObjectName objectName)
             throws InstanceAlreadyExistsException, MBeanRegistrationException, 
NotCompliantMBeanException {
+        if (mbs.isRegistered(objectName)) {
+            try {
+                mbs.unregisterMBean(objectName);
+            } catch (MBeanRegistrationException | InstanceNotFoundException 
ex) {
+                LOGGER.trace("Failed to unregister MBean {}", objectName);
+            }
+        }
         LOGGER.debug("Registering MBean {}", objectName);
         mbs.registerMBean(mbean, objectName);
     }
+
 }
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index dd1ecf0..4751456 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -75,6 +75,8 @@
         Allow a PatternSelector to be specified on GelfLayout.
       </action>
       <!-- FIXES -->
+      <action issue="LOG4J2-3121" dev="ggregory" type="fix" due-to="Markus 
Spann">
+          log4j2 config modified at run-time may trigger incomplete MBean 
re-initialization due to InstanceAlreadyExistsException.
       <action issue="LOG4J2-3107" dev="vy" type="fix" due-to="Markus Spann">
         SmtpManager.createManagerName ignores port.
       </action>

Reply via email to