8383 * via the {@link #setListeners(MBeanExporterListener[]) listeners} property, allowing
8484 * application code to be notified of MBean registration and unregistration events.
8585 *
86- * <p>This exporter is compatible with MBeans and MXBeans on Java 6 and above .
86+ * <p>This exporter is compatible with MBeans as well as MXBeans .
8787 *
8888 * @author Rob Harrop
8989 * @author Juergen Hoeller
@@ -466,7 +466,7 @@ public ObjectName registerManagedResource(Object managedResource) throws MBeanEx
466466 objectName = JmxUtils .appendIdentityToObjectName (objectName , managedResource );
467467 }
468468 }
469- catch (Exception ex ) {
469+ catch (Throwable ex ) {
470470 throw new MBeanExportException ("Unable to generate ObjectName for MBean [" + managedResource + "]" , ex );
471471 }
472472 registerManagedResource (managedResource , objectName );
@@ -570,15 +570,16 @@ protected boolean isBeanDefinitionLazyInit(ListableBeanFactory beanFactory, Stri
570570 * should be exposed to the {@code MBeanServer}. Specifically, if the
571571 * supplied {@code mapValue} is the name of a bean that is configured
572572 * for lazy initialization, then a proxy to the resource is registered with
573- * the {@code MBeanServer} so that the the lazy load behavior is
573+ * the {@code MBeanServer} so that the lazy load behavior is
574574 * honored. If the bean is already an MBean then it will be registered
575575 * directly with the {@code MBeanServer} without any intervention. For
576576 * all other beans or bean names, the resource itself is registered with
577577 * the {@code MBeanServer} directly.
578578 * @param mapValue the value configured for this bean in the beans map;
579579 * may be either the {@code String} name of a bean, or the bean itself
580580 * @param beanKey the key associated with this bean in the beans map
581- * @return the {@code ObjectName} under which the resource was registered
581+ * @return the {@code ObjectName} under which the resource was registered,
582+ * or {@code null} if the actual resource was {@code null} as well
582583 * @throws MBeanExportException if the export failed
583584 * @see #setBeans
584585 * @see #registerBeanInstance
@@ -599,12 +600,14 @@ protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey)
599600 }
600601 else {
601602 Object bean = this .beanFactory .getBean (beanName );
602- ObjectName objectName = registerBeanInstance (bean , beanKey );
603- replaceNotificationListenerBeanNameKeysIfNecessary (beanName , objectName );
604- return objectName ;
603+ if (bean != null ) {
604+ ObjectName objectName = registerBeanInstance (bean , beanKey );
605+ replaceNotificationListenerBeanNameKeysIfNecessary (beanName , objectName );
606+ return objectName ;
607+ }
605608 }
606609 }
607- else {
610+ else if ( mapValue != null ) {
608611 // Plain bean instance -> register it directly.
609612 if (this .beanFactory != null ) {
610613 Map <String , ?> beansOfSameType =
@@ -621,10 +624,11 @@ protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey)
621624 return registerBeanInstance (mapValue , beanKey );
622625 }
623626 }
624- catch (Exception ex ) {
627+ catch (Throwable ex ) {
625628 throw new UnableToRegisterMBeanException (
626629 "Unable to register MBean [" + mapValue + "] with key '" + beanKey + "'" , ex );
627630 }
631+ return null ;
628632 }
629633
630634 /**
@@ -816,7 +820,7 @@ protected ModelMBean createAndConfigureMBean(Object managedResource, String bean
816820 mbean .setManagedResource (managedResource , MR_TYPE_OBJECT_REFERENCE );
817821 return mbean ;
818822 }
819- catch (Exception ex ) {
823+ catch (Throwable ex ) {
820824 throw new MBeanExportException ("Could not create ModelMBean for managed resource [" +
821825 managedResource + "] with key '" + beanKey + "'" , ex );
822826 }
@@ -984,7 +988,7 @@ private void registerNotificationListeners() throws MBeanExportException {
984988 }
985989 }
986990 }
987- catch (Exception ex ) {
991+ catch (Throwable ex ) {
988992 throw new MBeanExportException ("Unable to register NotificationListener" , ex );
989993 }
990994 }
@@ -1004,7 +1008,7 @@ private void unregisterNotificationListeners() {
10041008 this .server .removeNotificationListener (mappedObjectName , bean .getNotificationListener (),
10051009 bean .getNotificationFilter (), bean .getHandback ());
10061010 }
1007- catch (Exception ex ) {
1011+ catch (Throwable ex ) {
10081012 if (logger .isDebugEnabled ()) {
10091013 logger .debug ("Unable to unregister NotificationListener" , ex );
10101014 }
0 commit comments