diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterHelper.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterHelper.java index 7ed7dc12c5..3ad0adb7b3 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterHelper.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterHelper.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.core.PriorityOrdered; import org.springframework.integration.monitor.IntegrationMBeanExporter; import org.springframework.jmx.export.MBeanExporter; +import org.springframework.util.StringUtils; /** * Most likely a temporary class mainly needed to address issue described in INT-2307. @@ -66,10 +67,13 @@ class MBeanExporterHelper implements BeanFactoryPostProcessor, BeanPostProcessor public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames(); for (String beanName : beanDefinitionNames) { - BeanDefinition bd = beanFactory.getBeanDefinition(beanName); + BeanDefinition bd = beanFactory.getMergedBeanDefinition(beanName); + String className = bd.getBeanClassName(); - if (className.startsWith(SI_ROOT_PACKAGE) && !(className.endsWith(IntegrationMBeanExporter.class.getName()))){ - siBeanNames.add(beanName); + if (StringUtils.hasText(className)){ + if (className.startsWith(SI_ROOT_PACKAGE) && !(className.endsWith(IntegrationMBeanExporter.class.getName()))){ + siBeanNames.add(beanName); + } } } } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanExporterHelperTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanExporterHelperTests.java new file mode 100644 index 0000000000..1f8bd45152 --- /dev/null +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanExporterHelperTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2002-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.springframework.integration.jmx.config; + +import org.junit.Test; + +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.support.RootBeanDefinition; + +/** + * @author Oleg Zhurakousky + * + */ +public class MBeanExporterHelperTests { + + @Test + public void testNoNpeWhenClassNameIsMissing(){ + DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); + RootBeanDefinition bd = new RootBeanDefinition(); + factory.registerBeanDefinition("foo", bd); + + MBeanExporterHelper helper = new MBeanExporterHelper(); + helper.postProcessBeanFactory(factory); + } + + @Test + public void testNoNpeWithAbstractBean(){ + DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); + RootBeanDefinition abstractBd = new RootBeanDefinition(); + abstractBd.setAbstract(true); + abstractBd.setBeanClass(String.class); + factory.registerBeanDefinition("abstractFoo", abstractBd); + RootBeanDefinition concreteBd = new RootBeanDefinition(abstractBd); + + factory.registerBeanDefinition("concreteFoo", concreteBd); + + MBeanExporterHelper helper = new MBeanExporterHelper(); + helper.postProcessBeanFactory(factory); + } +}