1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -446,7 +446,7 @@ public ObjectName registerManagedResource(Object managedResource) throws MBeanEx
446
446
objectName = JmxUtils .appendIdentityToObjectName (objectName , managedResource );
447
447
}
448
448
}
449
- catch (Exception ex ) {
449
+ catch (Throwable ex ) {
450
450
throw new MBeanExportException ("Unable to generate ObjectName for MBean [" + managedResource + "]" , ex );
451
451
}
452
452
registerManagedResource (managedResource , objectName );
@@ -548,15 +548,16 @@ protected boolean isBeanDefinitionLazyInit(ListableBeanFactory beanFactory, Stri
548
548
* should be exposed to the {@code MBeanServer}. Specifically, if the
549
549
* supplied {@code mapValue} is the name of a bean that is configured
550
550
* 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
552
552
* honored. If the bean is already an MBean then it will be registered
553
553
* directly with the {@code MBeanServer} without any intervention. For
554
554
* all other beans or bean names, the resource itself is registered with
555
555
* the {@code MBeanServer} directly.
556
556
* @param mapValue the value configured for this bean in the beans map;
557
557
* may be either the {@code String} name of a bean, or the bean itself
558
558
* @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
560
561
* @throws MBeanExportException if the export failed
561
562
* @see #setBeans
562
563
* @see #registerBeanInstance
@@ -577,12 +578,14 @@ protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey)
577
578
}
578
579
else {
579
580
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
+ }
583
586
}
584
587
}
585
- else {
588
+ else if ( mapValue != null ) {
586
589
// Plain bean instance -> register it directly.
587
590
if (this .beanFactory != null ) {
588
591
Map <String , ?> beansOfSameType =
@@ -599,10 +602,11 @@ protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey)
599
602
return registerBeanInstance (mapValue , beanKey );
600
603
}
601
604
}
602
- catch (Exception ex ) {
605
+ catch (Throwable ex ) {
603
606
throw new UnableToRegisterMBeanException (
604
607
"Unable to register MBean [" + mapValue + "] with key '" + beanKey + "'" , ex );
605
608
}
609
+ return null ;
606
610
}
607
611
608
612
/**
@@ -794,7 +798,7 @@ protected ModelMBean createAndConfigureMBean(Object managedResource, String bean
794
798
mbean .setManagedResource (managedResource , MR_TYPE_OBJECT_REFERENCE );
795
799
return mbean ;
796
800
}
797
- catch (Exception ex ) {
801
+ catch (Throwable ex ) {
798
802
throw new MBeanExportException ("Could not create ModelMBean for managed resource [" +
799
803
managedResource + "] with key '" + beanKey + "'" , ex );
800
804
}
@@ -960,7 +964,7 @@ private void registerNotificationListeners() throws MBeanExportException {
960
964
}
961
965
}
962
966
}
963
- catch (Exception ex ) {
967
+ catch (Throwable ex ) {
964
968
throw new MBeanExportException ("Unable to register NotificationListener" , ex );
965
969
}
966
970
}
@@ -980,7 +984,7 @@ private void unregisterNotificationListeners() {
980
984
this .server .removeNotificationListener (mappedObjectName , bean .getNotificationListener (),
981
985
bean .getNotificationFilter (), bean .getHandback ());
982
986
}
983
- catch (Exception ex ) {
987
+ catch (Throwable ex ) {
984
988
if (logger .isDebugEnabled ()) {
985
989
logger .debug ("Unable to unregister NotificationListener" , ex );
986
990
}
0 commit comments