Skip to content

Commit

Permalink
MBeanExporter silently ignores null beans
Browse files Browse the repository at this point in the history
Issue: SPR-15031
(cherry picked from commit 1e58c80)
  • Loading branch information
jhoeller committed Dec 19, 2016
1 parent b592dd7 commit e9def51
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
* via the {@link #setListeners(MBeanExporterListener[]) listeners} property, allowing
* application code to be notified of MBean registration and unregistration events.
*
* <p>This exporter is compatible with MBeans and MXBeans on Java 6 and above.
* <p>This exporter is compatible with MBeans as well as MXBeans.
*
* @author Rob Harrop
* @author Juergen Hoeller
Expand Down Expand Up @@ -466,7 +466,7 @@ public ObjectName registerManagedResource(Object managedResource) throws MBeanEx
objectName = JmxUtils.appendIdentityToObjectName(objectName, managedResource);
}
}
catch (Exception ex) {
catch (Throwable ex) {
throw new MBeanExportException("Unable to generate ObjectName for MBean [" + managedResource + "]", ex);
}
registerManagedResource(managedResource, objectName);
Expand Down Expand Up @@ -570,15 +570,16 @@ protected boolean isBeanDefinitionLazyInit(ListableBeanFactory beanFactory, Stri
* should be exposed to the {@code MBeanServer}. Specifically, if the
* supplied {@code mapValue} is the name of a bean that is configured
* for lazy initialization, then a proxy to the resource is registered with
* the {@code MBeanServer} so that the the lazy load behavior is
* the {@code MBeanServer} so that the lazy load behavior is
* honored. If the bean is already an MBean then it will be registered
* directly with the {@code MBeanServer} without any intervention. For
* all other beans or bean names, the resource itself is registered with
* the {@code MBeanServer} directly.
* @param mapValue the value configured for this bean in the beans map;
* may be either the {@code String} name of a bean, or the bean itself
* @param beanKey the key associated with this bean in the beans map
* @return the {@code ObjectName} under which the resource was registered
* @return the {@code ObjectName} under which the resource was registered,
* or {@code null} if the actual resource was {@code null} as well
* @throws MBeanExportException if the export failed
* @see #setBeans
* @see #registerBeanInstance
Expand All @@ -599,12 +600,14 @@ protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey)
}
else {
Object bean = this.beanFactory.getBean(beanName);
ObjectName objectName = registerBeanInstance(bean, beanKey);
replaceNotificationListenerBeanNameKeysIfNecessary(beanName, objectName);
return objectName;
if (bean != null) {
ObjectName objectName = registerBeanInstance(bean, beanKey);
replaceNotificationListenerBeanNameKeysIfNecessary(beanName, objectName);
return objectName;
}
}
}
else {
else if (mapValue != null) {
// Plain bean instance -> register it directly.
if (this.beanFactory != null) {
Map<String, ?> beansOfSameType =
Expand All @@ -621,10 +624,11 @@ protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey)
return registerBeanInstance(mapValue, beanKey);
}
}
catch (Exception ex) {
catch (Throwable ex) {
throw new UnableToRegisterMBeanException(
"Unable to register MBean [" + mapValue + "] with key '" + beanKey + "'", ex);
}
return null;
}

/**
Expand Down Expand Up @@ -816,7 +820,7 @@ protected ModelMBean createAndConfigureMBean(Object managedResource, String bean
mbean.setManagedResource(managedResource, MR_TYPE_OBJECT_REFERENCE);
return mbean;
}
catch (Exception ex) {
catch (Throwable ex) {
throw new MBeanExportException("Could not create ModelMBean for managed resource [" +
managedResource + "] with key '" + beanKey + "'", ex);
}
Expand Down Expand Up @@ -984,7 +988,7 @@ private void registerNotificationListeners() throws MBeanExportException {
}
}
}
catch (Exception ex) {
catch (Throwable ex) {
throw new MBeanExportException("Unable to register NotificationListener", ex);
}
}
Expand All @@ -1004,7 +1008,7 @@ private void unregisterNotificationListeners() {
this.server.removeNotificationListener(mappedObjectName, bean.getNotificationListener(),
bean.getNotificationFilter(), bean.getHandback());
}
catch (Exception ex) {
catch (Throwable ex) {
if (logger.isDebugEnabled()) {
logger.debug("Unable to unregister NotificationListener", ex);
}
Expand Down
Loading

0 comments on commit e9def51

Please sign in to comment.