fixed NPE due to the missing class name from BeanDefinition
This commit is contained in:
Oleg Zhurakousky
2011-12-20 15:34:29 -05:00
committed by Mark Fisher
parent df0e6bd51b
commit 03754b917a
2 changed files with 57 additions and 3 deletions

View File

@@ -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);
}
}
}
}

View File

@@ -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);
}
}