11/*
2- * Copyright 2002-2014 the original author or authors.
2+ * Copyright 2002-2016 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -446,7 +446,7 @@ public ObjectName registerManagedResource(Object managedResource) throws MBeanEx
446446 objectName = JmxUtils .appendIdentityToObjectName (objectName , managedResource );
447447 }
448448 }
449- catch (Exception ex ) {
449+ catch (Throwable ex ) {
450450 throw new MBeanExportException ("Unable to generate ObjectName for MBean [" + managedResource + "]" , ex );
451451 }
452452 registerManagedResource (managedResource , objectName );
@@ -548,15 +548,16 @@ protected boolean isBeanDefinitionLazyInit(ListableBeanFactory beanFactory, Stri
548548 * should be exposed to the {@code MBeanServer}. Specifically, if the
549549 * supplied {@code mapValue} is the name of a bean that is configured
550550 * for lazy initialization, then a proxy to the resource is registered with
551- * the {@code MBeanServer} so that the the lazy load behavior is
551+ * the {@code MBeanServer} so that the lazy load behavior is
552552 * honored. If the bean is already an MBean then it will be registered
553553 * directly with the {@code MBeanServer} without any intervention. For
554554 * all other beans or bean names, the resource itself is registered with
555555 * the {@code MBeanServer} directly.
556556 * @param mapValue the value configured for this bean in the beans map;
557557 * may be either the {@code String} name of a bean, or the bean itself
558558 * @param beanKey the key associated with this bean in the beans map
559- * @return the {@code ObjectName} under which the resource was registered
559+ * @return the {@code ObjectName} under which the resource was registered,
560+ * or {@code null} if the actual resource was {@code null} as well
560561 * @throws MBeanExportException if the export failed
561562 * @see #setBeans
562563 * @see #registerBeanInstance
@@ -577,12 +578,14 @@ protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey)
577578 }
578579 else {
579580 Object bean = this .beanFactory .getBean (beanName );
580- ObjectName objectName = registerBeanInstance (bean , beanKey );
581- replaceNotificationListenerBeanNameKeysIfNecessary (beanName , objectName );
582- return objectName ;
581+ if (bean != null ) {
582+ ObjectName objectName = registerBeanInstance (bean , beanKey );
583+ replaceNotificationListenerBeanNameKeysIfNecessary (beanName , objectName );
584+ return objectName ;
585+ }
583586 }
584587 }
585- else {
588+ else if ( mapValue != null ) {
586589 // Plain bean instance -> register it directly.
587590 if (this .beanFactory != null ) {
588591 Map <String , ?> beansOfSameType =
@@ -599,10 +602,11 @@ protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey)
599602 return registerBeanInstance (mapValue , beanKey );
600603 }
601604 }
602- catch (Exception ex ) {
605+ catch (Throwable ex ) {
603606 throw new UnableToRegisterMBeanException (
604607 "Unable to register MBean [" + mapValue + "] with key '" + beanKey + "'" , ex );
605608 }
609+ return null ;
606610 }
607611
608612 /**
@@ -794,7 +798,7 @@ protected ModelMBean createAndConfigureMBean(Object managedResource, String bean
794798 mbean .setManagedResource (managedResource , MR_TYPE_OBJECT_REFERENCE );
795799 return mbean ;
796800 }
797- catch (Exception ex ) {
801+ catch (Throwable ex ) {
798802 throw new MBeanExportException ("Could not create ModelMBean for managed resource [" +
799803 managedResource + "] with key '" + beanKey + "'" , ex );
800804 }
@@ -960,7 +964,7 @@ private void registerNotificationListeners() throws MBeanExportException {
960964 }
961965 }
962966 }
963- catch (Exception ex ) {
967+ catch (Throwable ex ) {
964968 throw new MBeanExportException ("Unable to register NotificationListener" , ex );
965969 }
966970 }
@@ -980,7 +984,7 @@ private void unregisterNotificationListeners() {
980984 this .server .removeNotificationListener (mappedObjectName , bean .getNotificationListener (),
981985 bean .getNotificationFilter (), bean .getHandback ());
982986 }
983- catch (Exception ex ) {
987+ catch (Throwable ex ) {
984988 if (logger .isDebugEnabled ()) {
985989 logger .debug ("Unable to unregister NotificationListener" , ex );
986990 }
0 commit comments