Bug 45932

Summary: Log4j JMX MBeans not cleaned up
Product: Log4j - Now in Jira Reporter: Howard <hmak>
Component: OtherAssignee: log4j-dev <log4j-dev>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: 1.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Howard 2008-10-01 13:43:00 UTC
LogManager.resetConfiguration() does not drop the JMX MBeans created by HierarchyDynamicMBean.

When executed twice, the following

	MBeanServer mbs = ...;
	Properties props = ...;
	HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
	mbs.registerMBean(hdm, new ObjectName("log4j:hiearchy=default"));

	Enumeration<Logger> iter = (Enumeration<Logger>) LogManager.getLoggerRepository().getCurrentLoggers();
	while (iter.hasMoreElements()) {
		hdm.addLoggerMBean(iter
			  .nextElement()
			  .getName());
	}

	LogManager.resetConfiguration();
	PropertyConfigurator.configure(props);

throws

	org.apache.log4j.jmx.LoggerDynamicMBean <ERROR  > Could not add appenderMBean for [F].
	javax.management.InstanceAlreadyExistsException: log4j:appender=F
		at com.sun.jmx.mbeanserver.RepositorySupport.addMBean(RepositorySupport.java:452)
		at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.internal_addObject(DefaultMBeanServerInterceptor.java:1410)
		at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:936)
		at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:337)
		at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:497)
		at org.apache.log4j.jmx.LoggerDynamicMBean.registerAppenderMBean(Unknown Source)
		at org.apache.log4j.jmx.LoggerDynamicMBean.handleNotification(Unknown Source)
		at javax.management.NotificationBroadcasterSupport.handleNotification(NotificationBroadcasterSupport.java:221)
		at javax.management.NotificationBroadcasterSupport.sendNotification(NotificationBroadcasterSupport.java:184)
		at org.apache.log4j.jmx.HierarchyDynamicMBean.addAppenderEvent(Unknown Source)
		at org.apache.log4j.Hierarchy.fireAddAppenderEvent(Hierarchy.java:192)
		at org.apache.log4j.Category.addAppender(Category.java:162)
		at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:614)
		at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:509)
		at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:415)
		at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:349)
		...